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

Upgrade apalis #2784

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 142 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ mas-templates = { path = "./crates/templates/", version = "=0.9.0" }
mas-tower = { path = "./crates/tower/", version = "=0.9.0" }
oauth2-types = { path = "./crates/oauth2-types/", version = "=0.9.0" }

# Async job queue
[workspace.dependencies.apalis]
version = "0.5.1"
features = ["cron"]

# GraphQL server
[workspace.dependencies.async-graphql]
version = "6.0.11"
Expand Down
16 changes: 11 additions & 5 deletions crates/cli/src/commands/manage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ impl Options {
let id = id.into();
info!(user.id = %id, "Scheduling provisioning job");
let job = ProvisionUserJob::new_for_id(id);
repo.job().schedule_job(job).await?;
repo.job().schedule_job(&mut rng, &clock, job).await?;
}

repo.into_inner().commit().await?;
Expand Down Expand Up @@ -350,7 +350,7 @@ impl Options {
}

let job = DeleteDeviceJob::new(&user, &compat_session.device);
repo.job().schedule_job(job).await?;
repo.job().schedule_job(&mut rng, &clock, job).await?;
repo.compat_session().finish(&clock, compat_session).await?;
}

Expand Down Expand Up @@ -383,7 +383,11 @@ impl Options {
if let Some(device) = Device::from_scope_token(scope) {
// Schedule a job to delete the device.
repo.job()
.schedule_job(DeleteDeviceJob::new(&user, &device))
.schedule_job(
&mut rng,
&clock,
DeleteDeviceJob::new(&user, &device),
)
.await?;
}
}
Expand Down Expand Up @@ -456,7 +460,7 @@ impl Options {
if deactivate {
warn!(%user.id, "Scheduling user deactivation");
repo.job()
.schedule_job(DeactivateUserJob::new(&user, false))
.schedule_job(&mut rng, &clock, DeactivateUserJob::new(&user, false))
.await?;
}

Expand Down Expand Up @@ -950,7 +954,9 @@ impl UserCreationRequest<'_> {
provision_job = provision_job.set_display_name(display_name);
}

repo.job().schedule_job(provision_job).await?;
repo.job()
.schedule_job(rng, clock, provision_job)
.await?;

Ok(user)
}
Expand Down
3 changes: 1 addition & 2 deletions crates/cli/src/commands/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ impl Options {

info!(worker_name, "Starting task worker");
let monitor =
mas_tasks::init(&worker_name, &pool, &mailer, homeserver_connection.clone())
.await?;
mas_tasks::init(&worker_name, &pool, &mailer, homeserver_connection.clone());
// TODO: grab the handle
tokio::spawn(monitor.run());
}
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/commands/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl Options {
let worker_name = Alphanumeric.sample_string(&mut rng, 10);

info!(worker_name, "Starting task scheduler");
let monitor = mas_tasks::init(&worker_name, &pool, &mailer, conn).await?;
let monitor = mas_tasks::init(&worker_name, &pool, &mailer, conn);

span.exit();

Expand Down
6 changes: 4 additions & 2 deletions crates/email/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ mod mailer;
mod transport;

pub use lettre::{
message::Mailbox, transport::smtp::authentication::Credentials as SmtpCredentials, Address,
address::{Address, AddressError},
message::Mailbox,
transport::smtp::authentication::Credentials as SmtpCredentials,
};
pub use mas_templates::EmailVerificationContext;

pub use self::{
mailer::Mailer,
mailer::{Error as MailerError, Mailer},
transport::{SmtpMode, Transport as MailTransport},
};
6 changes: 6 additions & 0 deletions crates/email/src/mailer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ pub struct Mailer {
reply_to: Mailbox,
}

/// Errors that can occur when sending emails
#[derive(Debug, Error)]
#[error(transparent)]
pub enum Error {
/// Mail failed to send through the transport
Transport(#[from] crate::transport::Error),

/// Failed to render email templates
Templates(#[from] mas_templates::TemplateError),

/// Email built was invalid
Content(#[from] lettre::error::Error),
}

Expand Down
Loading
Loading