Skip to content
Merged
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
52 changes: 11 additions & 41 deletions Cargo.lock

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

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,10 @@ rayon.opt-level = 3
regalloc2.opt-level = 3
sha2.opt-level = 3
sqlx-macros.opt-level = 3

[patch.crates-io]
sqlx = { git = "https://github.com/launchbadge/sqlx.git", branch = "main" }
sqlx-core = { git = "https://github.com/launchbadge/sqlx.git", branch = "main" }
sqlx-macros = { git = "https://github.com/launchbadge/sqlx.git", branch = "main" }
sqlx-macros-core = { git = "https://github.com/launchbadge/sqlx.git", branch = "main" }
sqlx-postgres = { git = "https://github.com/launchbadge/sqlx.git", branch = "main" }
2 changes: 2 additions & 0 deletions crates/cli/src/commands/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ impl Options {
&mailer,
homeserver_connection.clone(),
url_builder.clone(),
shutdown.soft_shutdown_token(),
shutdown.task_tracker(),
)
.await?;

Expand Down
39 changes: 34 additions & 5 deletions crates/cli/src/commands/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@ use rand::{
};
use tracing::{info, info_span};

use crate::util::{
database_pool_from_config, mailer_from_config, site_config_from_config, templates_from_config,
use crate::{
shutdown::ShutdownManager,
util::{
database_pool_from_config, mailer_from_config, site_config_from_config,
templates_from_config,
},
};

#[derive(Parser, Debug, Default)]
pub(super) struct Options {}

impl Options {
pub async fn run(self, figment: &Figment) -> anyhow::Result<ExitCode> {
let shutdown = ShutdownManager::new()?;
let span = info_span!("cli.worker.init").entered();
let config = AppConfig::extract(figment)?;

Expand Down Expand Up @@ -71,11 +76,35 @@ 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, url_builder).await?;

let monitor = mas_tasks::init(
&worker_name,
&pool,
&mailer,
conn,
url_builder,
shutdown.soft_shutdown_token(),
shutdown.task_tracker(),
)
.await?;

// XXX: The monitor from apalis is a bit annoying to use for graceful shutdowns,
// ideally we'd just give it a cancellation token
let shutdown_future = shutdown.soft_shutdown_token().cancelled_owned();
shutdown.task_tracker().spawn(async move {
if let Err(e) = monitor
.run_with_signal(async move {
shutdown_future.await;
Ok(())
})
.await
{
tracing::error!(error = &e as &dyn std::error::Error, "Task worker failed");
}
});
span.exit();

monitor.run().await?;
shutdown.run().await;

Ok(ExitCode::SUCCESS)
}
}

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

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

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

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

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

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

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

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

Loading
Loading