From ac7cd266feb6ad43acd4605776888ead015f5dd3 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Sat, 23 May 2026 21:01:27 -0600 Subject: [PATCH] Add Apalis job timeout (15m) --- crates/core/src/config.rs | 12 +++++++++++- crates/jobs/src/lib.rs | 11 +++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/crates/core/src/config.rs b/crates/core/src/config.rs index b13f6b2..37b190e 100644 --- a/crates/core/src/config.rs +++ b/crates/core/src/config.rs @@ -61,10 +61,20 @@ pub struct WorkerConfig { pub refresh_project_concurrency: usize, /// Number of retry attempts for failed jobs. pub retry_attempts: usize, + /// Maximum wall-clock seconds allowed for a single job attempt. + #[serde(default = "default_job_timeout_secs")] + pub job_timeout_secs: u64, } impl Default for WorkerConfig { fn default() -> Self { - Self { workflow_run_concurrency: 3, refresh_project_concurrency: 3, retry_attempts: 5 } + Self { + workflow_run_concurrency: 3, + refresh_project_concurrency: 3, + retry_attempts: 5, + job_timeout_secs: default_job_timeout_secs(), + } } } + +fn default_job_timeout_secs() -> u64 { 15 * 60 } diff --git a/crates/jobs/src/lib.rs b/crates/jobs/src/lib.rs index 1b9880a..207dc9c 100644 --- a/crates/jobs/src/lib.rs +++ b/crates/jobs/src/lib.rs @@ -86,8 +86,13 @@ pub fn create_monitor( context: JobContext, config: &WorkerConfig, ) -> Monitor { - let &WorkerConfig { workflow_run_concurrency, refresh_project_concurrency, retry_attempts } = - config; + let &WorkerConfig { + workflow_run_concurrency, + refresh_project_concurrency, + retry_attempts, + job_timeout_secs, + } = config; + let job_timeout = Duration::from_secs(job_timeout_secs); let backoff = ExponentialBackoffMaker::new( Duration::from_secs(1), @@ -112,6 +117,7 @@ pub fn create_monitor( .register(move |_| { WorkerBuilder::new("workflow-run-worker") .backend(storage1.workflow_run.clone()) + .timeout(job_timeout) .retry(retry1.clone()) .enable_tracing() .catch_panic() @@ -128,6 +134,7 @@ pub fn create_monitor( .register(move |_| { WorkerBuilder::new("refresh-project-worker") .backend(storage2.refresh_project.clone()) + .timeout(job_timeout) .retry(retry2.clone()) .enable_tracing() .catch_panic()