You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-11-20 12:02:22 +03:00
mas-tasks: refactor worker building behind a macro
This commit is contained in:
@@ -107,6 +107,32 @@ impl JobContextExt for apalis_core::context::JobContext {
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper macro to build a storage-backed worker.
|
||||
macro_rules! build {
|
||||
($job:ty => $fn:ident, $suffix:expr, $state:expr, $factory:expr) => {{
|
||||
let storage = $factory.build();
|
||||
let worker_name = format!(
|
||||
"{job}-{suffix}",
|
||||
job = <$job as ::apalis_core::job::Job>::NAME,
|
||||
suffix = $suffix
|
||||
);
|
||||
|
||||
let builder = ::apalis_core::builder::WorkerBuilder::new(worker_name)
|
||||
.layer($state.inject())
|
||||
.layer(crate::utils::trace_layer())
|
||||
.layer(crate::utils::metrics_layer());
|
||||
|
||||
let builder = ::apalis_core::storage::builder::WithStorage::with_storage_config(
|
||||
builder,
|
||||
storage,
|
||||
|c| c.fetch_interval(std::time::Duration::from_secs(1)),
|
||||
);
|
||||
::apalis_core::builder::WorkerFactory::build(builder, ::apalis_core::job_fn::job_fn($fn))
|
||||
}};
|
||||
}
|
||||
|
||||
pub(crate) use build;
|
||||
|
||||
/// Initialise the workers.
|
||||
///
|
||||
/// # Errors
|
||||
|
||||
Reference in New Issue
Block a user