Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.

Commit 94792ed

Browse files
committed
Use apalis instead of apalis_core in most places
1 parent 4d1acb2 commit 94792ed

File tree

11 files changed

+141
-30
lines changed

11 files changed

+141
-30
lines changed

Cargo.lock

+112-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ mas-templates = { path = "./crates/templates/", version = "=0.9.0" }
5555
mas-tower = { path = "./crates/tower/", version = "=0.9.0" }
5656
oauth2-types = { path = "./crates/oauth2-types/", version = "=0.9.0" }
5757

58+
# Async job queue
59+
[workspace.dependencies.apalis]
60+
version = "0.4.9"
61+
features = ["cron"]
62+
5863
# GraphQL server
5964
[workspace.dependencies.async-graphql]
6065
version = "6.0.11"

crates/storage/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ chrono.workspace = true
1717
thiserror.workspace = true
1818
futures-util = "0.3.30"
1919

20-
apalis-core = { version = "0.4.9", features = ["tokio-comp"] }
20+
apalis.workspace = true
2121
opentelemetry.workspace = true
2222
rand_core = "0.6.4"
2323
serde.workspace = true

crates/storage/src/job.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
1717
use std::{num::ParseIntError, ops::Deref};
1818

19-
pub use apalis_core::job::Job;
19+
pub use apalis::prelude::Job;
2020
use async_trait::async_trait;
2121
use opentelemetry::trace::{SpanContext, SpanId, TraceContextExt, TraceFlags, TraceId, TraceState};
2222
use rand_core::RngCore;
@@ -250,7 +250,7 @@ where
250250

251251
mod jobs {
252252
// XXX: Move this somewhere else?
253-
use apalis_core::job::Job;
253+
use apalis::prelude::Job;
254254
use mas_data_model::{Device, User, UserEmail};
255255
use serde::{Deserialize, Serialize};
256256
use ulid::Ulid;

crates/tasks/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ workspace = true
1313

1414
[dependencies]
1515
anyhow.workspace = true
16-
apalis-core = { version = "0.4.9", features = ["extensions", "tokio-comp", "storage"] }
17-
apalis-cron = "0.4.9"
16+
apalis.workspace = true
17+
apalis-core = "0.4.9"
1818
async-stream = "0.3.5"
1919
async-trait.workspace = true
2020
chrono.workspace = true

crates/tasks/src/database.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,12 @@
1616
1717
use std::str::FromStr;
1818

19-
use apalis_core::{
20-
builder::{WorkerBuilder, WorkerFactoryFn},
21-
context::JobContext,
22-
executor::TokioExecutor,
23-
job::Job,
24-
monitor::Monitor,
25-
utils::timer::TokioTimer,
19+
use apalis::{
20+
cron::CronStream,
21+
prelude::{
22+
timer::TokioTimer, Job, JobContext, Monitor, TokioExecutor, WorkerBuilder, WorkerFactoryFn,
23+
},
2624
};
27-
use apalis_cron::CronStream;
2825
use chrono::{DateTime, Utc};
2926
use mas_storage::{oauth2::OAuth2AccessTokenRepository, RepositoryAccess};
3027
use tracing::{debug, info};
@@ -78,7 +75,7 @@ pub(crate) fn register(
7875
monitor: Monitor<TokioExecutor>,
7976
state: &State,
8077
) -> Monitor<TokioExecutor> {
81-
let schedule = apalis_cron::Schedule::from_str("*/15 * * * * *").unwrap();
78+
let schedule = apalis::cron::Schedule::from_str("*/15 * * * * *").unwrap();
8279
let worker_name = format!("{job}-{suffix}", job = CleanupExpiredTokensJob::NAME);
8380
let worker = WorkerBuilder::new(worker_name)
8481
.stream(CronStream::new(schedule).timer(TokioTimer).to_stream())

crates/tasks/src/email.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
use anyhow::Context;
16-
use apalis_core::{context::JobContext, executor::TokioExecutor, monitor::Monitor};
16+
use apalis::prelude::{JobContext, Monitor, TokioExecutor};
1717
use chrono::Duration;
1818
use mas_email::{Address, Mailbox};
1919
use mas_i18n::locale;

crates/tasks/src/lib.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515
use std::sync::Arc;
1616

17-
use apalis_core::{executor::TokioExecutor, layers::extensions::Extension, monitor::Monitor};
17+
use apalis::prelude::{Monitor, TokioExecutor};
18+
use apalis_core::layers::extensions::Extension;
1819
use mas_email::Mailer;
1920
use mas_matrix::HomeserverConnection;
2021
use mas_storage::{BoxClock, BoxRepository, Repository, SystemClock};
@@ -95,7 +96,7 @@ trait JobContextExt {
9596
fn state(&self) -> State;
9697
}
9798

98-
impl JobContextExt for apalis_core::context::JobContext {
99+
impl JobContextExt for apalis::prelude::JobContext {
99100
fn state(&self) -> State {
100101
self.data_opt::<State>()
101102
.expect("state not injected in job context")
@@ -109,21 +110,19 @@ macro_rules! build {
109110
let storage = $factory.build();
110111
let worker_name = format!(
111112
"{job}-{suffix}",
112-
job = <$job as ::apalis_core::job::Job>::NAME,
113+
job = <$job as ::apalis::prelude::Job>::NAME,
113114
suffix = $suffix
114115
);
115116

116-
let builder = ::apalis_core::builder::WorkerBuilder::new(worker_name)
117+
let builder = ::apalis::prelude::WorkerBuilder::new(worker_name)
117118
.layer($state.inject())
118119
.layer(crate::utils::trace_layer())
119120
.layer(crate::utils::metrics_layer());
120121

121-
let builder = ::apalis_core::storage::builder::WithStorage::with_storage_config(
122-
builder,
123-
storage,
124-
|c| c.fetch_interval(std::time::Duration::from_secs(1)),
125-
);
126-
::apalis_core::builder::WorkerFactory::build(builder, ::apalis_core::job_fn::job_fn($fn))
122+
let builder = ::apalis::prelude::WithStorage::with_storage_config(builder, storage, |c| {
123+
c.fetch_interval(std::time::Duration::from_secs(1))
124+
});
125+
::apalis::prelude::WorkerFactory::build(builder, ::apalis::prelude::job_fn($fn))
127126
}};
128127
}
129128

crates/tasks/src/matrix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
use anyhow::Context;
16-
use apalis_core::{context::JobContext, executor::TokioExecutor, monitor::Monitor};
16+
use apalis::prelude::{JobContext, Monitor, TokioExecutor};
1717
use mas_matrix::ProvisionRequest;
1818
use mas_storage::{
1919
job::{DeleteDeviceJob, JobWithSpanContext, ProvisionDeviceJob, ProvisionUserJob},

crates/tasks/src/user.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
use anyhow::Context;
16-
use apalis_core::{context::JobContext, executor::TokioExecutor, monitor::Monitor};
16+
use apalis::prelude::{JobContext, Monitor, TokioExecutor};
1717
use mas_storage::{
1818
job::{DeactivateUserJob, JobWithSpanContext},
1919
user::UserRepository,

crates/tasks/src/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use apalis_core::{job::Job, request::JobRequest};
15+
use apalis::{prelude::Job, prelude::JobRequest};
1616
use mas_storage::job::JobWithSpanContext;
1717
use mas_tower::{
1818
make_span_fn, DurationRecorderLayer, FnWrapper, IdentityLayer, InFlightCounterLayer,

0 commit comments

Comments
 (0)