umpx

Check-in Differences
Login

Check-in Differences

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Difference From umpx-0.0.1 To trunk

2024-09-10
04:22
Start pedantic clippy cleanup. Leaf check-in: bc88506507 user: jan tags: trunk
2024-08-07
09:30
keywords. check-in: 8bb4b9ac3e user: jan tags: trunk, umpx-0.0.1
07:43
Rephrase. check-in: 40497e1ec9 user: jan tags: trunk

Changes to Cargo.toml.

1
2
3

4
5
6
7
8
9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24
25
26
27
28
29

30
31
32


33
34
35
36
37
1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

30
31


32
33
34
35
36
37
38


-
+













+












-
+

-
-
+
+





[package]
name = "umpx"
version = "0.0.1"
version = "0.0.2"
edition = "2021"
license = "0BSD"
# https://crates.io/category_slugs
categories = [ "concurrency", "asynchronous" ]
keywords = [ "ump", "message-passing" ]
repository = "https://repos.qrnch.tech/pub/umpx"
description = "Collection of ump extensions."
rust-version = "1.56"
exclude = [
  ".fossil-settings",
  ".efiles",
  ".fslckout",
  "www",
  "bacon.toml",
  "rustfmt.toml"
]

# https://doc.rust-lang.org/cargo/reference/manifest.html#the-badges-section
[badges]
maintenance = { status = "experimental" }

[features]
sqlsrv = ["dep:sqlsrv", "sqlsrv/tpool", "dep:threadpool"]

[dependencies]
sqlsrv = { version = "0.5.0", optional = true }
swctx = { version = "0.2.2" }
swctx = { version = "0.3.0" }
threadpool = { version = "1.8.1", optional = true }
ump = { version = "0.12.1" }
ump-server = { version = "0.3.0" }
ump = { version = "0.13.0" }
ump-server = { version = "0.4.0" }

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"]

Added bacon.toml.



































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
# This is a configuration file for the bacon tool
#
# Bacon repository: https://github.com/Canop/bacon
# Complete help on configuration: https://dystroy.org/bacon/config/
# You can also check bacon's own bacon.toml file
#  as an example: https://github.com/Canop/bacon/blob/main/bacon.toml

# For information about clippy lints, see:
# https://github.com/rust-lang/rust-clippy/blob/master/README.md

#default_job = "check"
default_job = "clippy-all-pedantic"

[jobs.check]
command = ["cargo", "check", "--color", "always"]
need_stdout = false

[jobs.check-all]
command = ["cargo", "check", "--all-targets", "--color", "always"]
need_stdout = false

# Run clippy on the default target
[jobs.clippy]
command = [
    "cargo", "clippy",
    "--color", "always",
]
need_stdout = false

# Run clippy on all targets
# To disable some lints, you may change the job this way:
#    [jobs.clippy-all]
#    command = [
#        "cargo", "clippy",
#        "--all-targets",
#        "--color", "always",
#    	 "--",
#    	 "-A", "clippy::bool_to_int_with_if",
#    	 "-A", "clippy::collapsible_if",
#    	 "-A", "clippy::derive_partial_eq_without_eq",
#    ]
# need_stdout = false
[jobs.clippy-all]
command = [
    "cargo", "clippy",
    "--all-targets",
    "--color", "always",
]
need_stdout = false

[jobs.clippy-pedantic]
command = [
    "cargo", "clippy",
    "--color", "always",
    "--",
    "-Wclippy::all",
    "-Wclippy::pedantic",
    "-Wclippy::nursery",
    "-Wclippy::cargo"
]
need_stdout = false

[jobs.clippy-all-pedantic]
command = [
    "cargo", "clippy",
    "--all-targets",
    "--color", "always",
    "--",
    "-Wclippy::all",
    "-Wclippy::pedantic",
    "-Wclippy::nursery",
    "-Wclippy::cargo"
]
need_stdout = false

# This job lets you run
# - all tests: bacon test
# - a specific test: bacon test -- config::test_default_files
# - the tests of a package: bacon test -- -- -p config
[jobs.test]
command = [
    "cargo", "test", "--color", "always",
    "--", "--color", "always", # see https://github.com/Canop/bacon/issues/124
]
need_stdout = true

[jobs.doc]
command = ["cargo", "doc", "--color", "always", "--no-deps"]
need_stdout = false

# If the doc compiles, then it opens in your browser and bacon switches
# to the previous job
[jobs.doc-open]
command = ["cargo", "doc", "--color", "always", "--no-deps", "--open"]
need_stdout = false
on_success = "back" # so that we don't open the browser at each change

# You can run your application and have the result displayed in bacon,
# *if* it makes sense for this crate.
# Don't forget the `--color always` part or the errors won't be
# properly parsed.
# If your program never stops (eg a server), you may set `background`
# to false to have the cargo run output immediately displayed instead
# of waiting for program's end.
[jobs.run]
command = [
    "cargo", "run",
    "--color", "always",
    # put launch parameters for your program behind a `--` separator
]
need_stdout = true
allow_warnings = true
background = true

# This parameterized job runs the example of your choice, as soon
# as the code compiles.
# Call it as
#    bacon ex -- my-example
[jobs.ex]
command = ["cargo", "run", "--color", "always", "--example"]
need_stdout = true
allow_warnings = true

# You may define here keybindings that would be specific to
# a project, for example a shortcut to launch a specific job.
# Shortcuts to internal functions (scrolling, toggling, etc.)
# should go in your personal global prefs.toml file instead.
[keybindings]
# alt-m = "job:my-job"
c = "job:clippy-all" # comment this to have 'c' run clippy on only the default target

Changes to src/server/sqlsrv/utils.rs.

1
2
3
4
5
6
7
8
9
10
11
1
2


3
4
5
6
7
8
9


-
-







//! Integration utilities for creating sqlsrv handlers.

use std::fmt;

use super::{
  r2d2,
  rusqlite::{params, Connection},
  ConnPool, WrConn
};

use threadpool::ThreadPool;
23
24
25
26
27
28
29
30

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146

147
148
149
150
151
152
153
154
155
156

157
158
159
160
161
162

163
164



165
166
167
168
169
170
171
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35
36
37



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

58
59
60
61
62
63
64
65
66
67
68



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

85
86
87
88
89
90
91
92
93
94



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111

112
113
114
115
116
117
118
119
120
121
122



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149

150
151
152
153
154
155
156
157
158
159
160
161
162







-
+









-
-
-




















-
+










-
-
-
















-
+









-
-
-

















-
+










-
-
-










+










+





-
+


+
+
+







pub fn proc_rodb_req<R, E, F>(
  cpool: &ConnPool,
  rctx: ReplyContext<R, E>,
  f: F
) -> Result<(), r2d2::Error>
where
  R: Send + 'static,
  E: fmt::Debug + Send + 'static,
  E: std::error::Error + Send + 'static,
  F: FnOnce(&Connection) -> Result<R, E> + Send + 'static
{
  let roconn = cpool.reader()?;

  let res = match f(&roconn) {
    Ok(reply) => rctx.reply(reply),
    Err(e) => rctx.fail(e)
  };
  if let Err(e) = res {
    // Note: This can currently not happen.
    // Leave a printout here as a reminder in case that changes in the
    // future.
    eprintln!("Reply message pass failed; {}", e);
  }

  Ok(())
}


/// Given an [`ConnPool`], a [`ThreadPool`] and a [`ReplyContext`], run a
/// closure (presumably performing read-only database operations) on a thread.
///
/// Translates the closure's `Result<T, E>` into a `ReplyContext::reply()` on
/// `Ok` and `ReplyContext::fail()` on `Err`.
pub fn proc_rodb_req_thrd<R, E, F>(
  cpool: &ConnPool,
  tpool: &ThreadPool,
  rctx: ReplyContext<R, E>,
  f: F
) -> Result<(), r2d2::Error>
where
  R: Send + 'static,
  E: fmt::Debug + Send + 'static,
  E: std::error::Error + Send + 'static,
  F: FnOnce(&Connection) -> Result<R, E> + Send + 'static
{
  let roconn = cpool.reader()?;

  tpool.execute(move || {
    let res = match f(&roconn) {
      Ok(reply) => rctx.reply(reply),
      Err(e) => rctx.fail(e)
    };
    if let Err(e) = res {
      // Note: This can currently not happen.
      // Leave a printout here as a reminder in case that changes in the
      // future.
      eprintln!("Reply message pass failed; {}", e);
    }
  });

  Ok(())
}


/// Given an [`ConnPool`] and a [`ReplyContext`], run a
/// closure (presumably performing read/write database operations) on a thread.
///
/// Translates the closure's `Result<T, E>` into a `ReplyContext::reply()` on
/// `Ok` and `ReplyContext::fail()` on `Err`.
pub fn proc_rwdb_req<R, E, F>(cpool: &ConnPool, rctx: ReplyContext<R, E>, f: F)
where
  R: Send + 'static,
  E: fmt::Debug + Send + 'static,
  E: std::error::Error + Send + 'static,
  F: FnOnce(&mut WrConn) -> Result<R, E> + Send + 'static
{
  let mut rwconn = cpool.writer();

  let res = match f(&mut rwconn) {
    Ok(reply) => rctx.reply(reply),
    Err(e) => rctx.fail(e)
  };
  if let Err(e) = res {
    // Note: This can currently not happen
    // Leave a printout here as a reminder in case that changes in the
    // future.
    eprintln!("Reply message pass failed; {}", e);
  }
}


/// Given an [`ConnPool`], a [`ThreadPool`] and a [`ReplyContext`], run a
/// closure (presumably performing read/write database operations) on a thread.
///
/// Translates the closure's `Result<T, E>` into a `ReplyContext::reply()` on
/// `Ok` and `ReplyContext::fail()` on `Err`.
pub fn proc_rwdb_req_thrd<R, E, F>(
  cpool: &ConnPool,
  tpool: &ThreadPool,
  rctx: ReplyContext<R, E>,
  f: F
) where
  R: Send + 'static,
  E: fmt::Debug + Send + 'static,
  E: std::error::Error + Send + 'static,
  F: FnOnce(&mut WrConn) -> Result<R, E> + Send + 'static
{
  let mut rwconn = cpool.writer();

  tpool.execute(move || {
    let res = match f(&mut rwconn) {
      Ok(reply) => rctx.reply(reply),
      Err(e) => rctx.fail(e)
    };
    if let Err(e) = res {
      // Note: This can currently not happen
      // Leave a printout here as a reminder in case that changes in the
      // future.
      eprintln!("Reply message pass failed; {}", e);
    }
  });
}


/// Perform an incremental vacuum.
///
/// `n` is the number of freelist nodes to reclaim.  If `None` all nodes will
/// be reclaimed.
#[must_use]
pub fn incremental_vacuum(
  cpool: &ConnPool,
  tpool: &ThreadPool,
  n: Option<usize>
) -> swctx::WaitCtx<(), (), rusqlite::Error> {
  let (sctx, wctx) = swctx::mkpair();

  let conn = cpool.writer();

  tpool.execute(move || {
    #[allow(clippy::option_if_let_else)]
    let res = if let Some(n) = n {
      conn.execute("PRAGMA incremental_vacuum(?);", params![n])
    } else {
      conn.execute("PRAGMA incremental_vacuum;", params![])
    };
    match res {
    let res = match res {
      Ok(_) => sctx.set(()),
      Err(e) => sctx.fail(e)
    };
    if let Err(e) = res {
      eprintln!("Reply message pass failed; {}", e);
    }
  });

  wctx
}

// vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :