mirror of
https://github.com/Diggsey/sqlxmq.git
synced 2024-05-29 06:28:13 +00:00
Compare commits
2 commits
75e12bac6c
...
c1d7ad4a2f
Author | SHA1 | Date | |
---|---|---|---|
c1d7ad4a2f | |||
5e4f160d91 |
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
|
@ -1,4 +1,7 @@
|
||||||
{
|
{
|
||||||
"rust-analyzer.checkOnSave.allFeatures": false,
|
"rust-analyzer.checkOnSave.allFeatures": false,
|
||||||
"rust-analyzer.cargo.allFeatures": false
|
"rust-analyzer.cargo.allFeatures": false,
|
||||||
|
"rust-analyzer.cargo.features": [
|
||||||
|
"runtime-tokio-native-tls"
|
||||||
|
]
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "sqlxmq"
|
name = "sqlxmq"
|
||||||
version = "0.4.1"
|
version = "0.5.0"
|
||||||
authors = ["Diggory Blake <diggsey@googlemail.com>"]
|
authors = ["Diggory Blake <diggsey@googlemail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
|
@ -15,7 +15,7 @@ members = ["sqlxmq_macros", "sqlxmq_stress"]
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
sqlx = { version = "0.6.0", features = ["postgres", "chrono", "uuid"] }
|
sqlx = { version = "0.7.1", features = ["postgres", "chrono", "uuid"] }
|
||||||
tokio = { version = "1.8.3", features = ["full"] }
|
tokio = { version = "1.8.3", features = ["full"] }
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
chrono = "0.4.19"
|
chrono = "0.4.19"
|
||||||
|
@ -23,7 +23,7 @@ uuid = { version = "1.1.2", features = ["v4"] }
|
||||||
log = "0.4.14"
|
log = "0.4.14"
|
||||||
serde_json = "1.0.64"
|
serde_json = "1.0.64"
|
||||||
serde = "1.0.124"
|
serde = "1.0.124"
|
||||||
sqlxmq_macros = { version = "0.4.1", path = "sqlxmq_macros" }
|
sqlxmq_macros = { version = "0.5.0", path = "sqlxmq_macros" }
|
||||||
anymap2 = "0.13.0"
|
anymap2 = "0.13.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "sqlxmq_macros"
|
name = "sqlxmq_macros"
|
||||||
version = "0.4.1"
|
version = "0.5.0"
|
||||||
authors = ["Diggory Blake <diggsey@googlemail.com>"]
|
authors = ["Diggory Blake <diggsey@googlemail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
|
|
|
@ -15,10 +15,13 @@ use crate::hidden::{BuildFn, RunFn};
|
||||||
use crate::utils::Opaque;
|
use crate::utils::Opaque;
|
||||||
use crate::{JobBuilder, JobRunnerOptions};
|
use crate::{JobBuilder, JobRunnerOptions};
|
||||||
|
|
||||||
|
type BoxedError = Box<dyn Error + Send + 'static>;
|
||||||
|
|
||||||
/// Stores a mapping from job name to job. Can be used to construct
|
/// Stores a mapping from job name to job. Can be used to construct
|
||||||
/// a job runner.
|
/// a job runner.
|
||||||
pub struct JobRegistry {
|
pub struct JobRegistry {
|
||||||
error_handler: Arc<dyn Fn(&str, Box<dyn Error + Send + 'static>) + Send + Sync>,
|
#[allow(clippy::type_complexity)]
|
||||||
|
error_handler: Arc<dyn Fn(&str, BoxedError) + Send + Sync>,
|
||||||
job_map: HashMap<&'static str, &'static NamedJob>,
|
job_map: HashMap<&'static str, &'static NamedJob>,
|
||||||
context: Map<dyn CloneAnySendSync + Send + Sync>,
|
context: Map<dyn CloneAnySendSync + Send + Sync>,
|
||||||
}
|
}
|
||||||
|
@ -53,7 +56,7 @@ impl JobRegistry {
|
||||||
/// Set a function to be called whenever a job returns an error.
|
/// Set a function to be called whenever a job returns an error.
|
||||||
pub fn set_error_handler(
|
pub fn set_error_handler(
|
||||||
&mut self,
|
&mut self,
|
||||||
error_handler: impl Fn(&str, Box<dyn Error + Send + 'static>) + Send + Sync + 'static,
|
error_handler: impl Fn(&str, BoxedError) + Send + Sync + 'static,
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
self.error_handler = Arc::new(error_handler);
|
self.error_handler = Arc::new(error_handler);
|
||||||
self
|
self
|
||||||
|
@ -83,7 +86,7 @@ impl JobRegistry {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The default error handler implementation, which simply logs the error.
|
/// The default error handler implementation, which simply logs the error.
|
||||||
pub fn default_error_handler(name: &str, error: Box<dyn Error + Send + 'static>) {
|
pub fn default_error_handler(name: &str, error: BoxedError) {
|
||||||
log::error!("Job `{}` failed: {}", name, error);
|
log::error!("Job `{}` failed: {}", name, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -142,7 +142,7 @@ impl CurrentJob {
|
||||||
&mut self,
|
&mut self,
|
||||||
mut tx: sqlx::Transaction<'_, Postgres>,
|
mut tx: sqlx::Transaction<'_, Postgres>,
|
||||||
) -> Result<(), sqlx::Error> {
|
) -> Result<(), sqlx::Error> {
|
||||||
self.delete(&mut tx).await?;
|
self.delete(&mut *tx).await?;
|
||||||
tx.commit().await?;
|
tx.commit().await?;
|
||||||
self.stop_keep_alive().await;
|
self.stop_keep_alive().await;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -161,7 +161,7 @@ impl CurrentJob {
|
||||||
mut tx: sqlx::Transaction<'_, Postgres>,
|
mut tx: sqlx::Transaction<'_, Postgres>,
|
||||||
checkpoint: &Checkpoint<'_>,
|
checkpoint: &Checkpoint<'_>,
|
||||||
) -> Result<(), sqlx::Error> {
|
) -> Result<(), sqlx::Error> {
|
||||||
checkpoint.execute(self.id, &mut tx).await?;
|
checkpoint.execute(self.id, &mut *tx).await?;
|
||||||
tx.commit().await?;
|
tx.commit().await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue