From f826a87a59cd839df30ca539ad197639c165a8fc Mon Sep 17 00:00:00 2001 From: "Aode (lion)" Date: Wed, 17 Nov 2021 11:43:14 -0600 Subject: [PATCH] Return error when failing to spawn enqueue --- jobs-actix/Cargo.toml | 2 +- jobs-actix/src/lib.rs | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/jobs-actix/Cargo.toml b/jobs-actix/Cargo.toml index 0e01151..e12d48f 100644 --- a/jobs-actix/Cargo.toml +++ b/jobs-actix/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "background-jobs-actix" description = "in-process jobs processor based on Actix" -version = "0.9.4" +version = "0.9.5" license-file = "../LICENSE" authors = ["asonix "] repository = "https://git.asonix.dog/Aardwolf/background-jobs" diff --git a/jobs-actix/src/lib.rs b/jobs-actix/src/lib.rs index 1fdc11b..3ed1b5c 100644 --- a/jobs-actix/src/lib.rs +++ b/jobs-actix/src/lib.rs @@ -271,11 +271,14 @@ impl QueueHandle { { let job = new_job(job)?; let server = self.inner.clone(); - self.arbiter.spawn(async move { + let success = self.arbiter.spawn(async move { if let Err(e) = server.new_job(job).await { error!("Error creating job, {}", e); } }); + if !success { + return Err(anyhow::anyhow!("Failed to queue job")); + } Ok(()) } @@ -289,11 +292,14 @@ impl QueueHandle { { let job = new_scheduled_job(job, after)?; let server = self.inner.clone(); - self.arbiter.spawn(async move { + let success = self.arbiter.spawn(async move { if let Err(e) = server.new_job(job).await { error!("Error creating job, {}", e); } }); + if !success { + return Err(anyhow::anyhow!("Failed to schedule job")); + } Ok(()) }