Skip to content

Commit

Permalink
feat: Add AppWorker#enqueue_delayed (#531)
Browse files Browse the repository at this point in the history
Allow enqueuing delayed sidekiq jobs via the `AppWorker` trait.
  • Loading branch information
spencewenski authored Dec 23, 2024
1 parent d0dac4a commit 2f5bdf9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#![deny(clippy::expect_used)]
// Ignore the warning that the `coverage_nightly` cfg is not recognized.
#![cfg_attr(test, allow(unexpected_cfgs))]
// https://github.com/taiki-e/coverage-helper?tab=readme-ov-file#usage
#![cfg_attr(all(test, coverage_nightly), feature(coverage_attribute))]

pub mod api;
pub mod app;
Expand Down
8 changes: 8 additions & 0 deletions src/service/worker/sidekiq/app_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ where
Ok(())
}

/// Enqueue the worker into its Sidekiq queue. This is a helper method around [Worker::perform_in]
/// so the caller can simply provide the app state instead of needing to access the
/// [sidekiq::RedisPool] from inside the app state.
async fn enqueue_delayed(state: &S, delay: Duration, args: Args) -> RoadsterResult<()> {
Self::perform_in(AppContext::from_ref(state).redis_enqueue(), delay, args).await?;
Ok(())
}

/// Provide the [AppWorkerConfig] for [Self]. The default implementation populates the
/// [AppWorkerConfig] using the values from the corresponding methods on [Self], e.g.,
/// [Self::max_retries].
Expand Down

0 comments on commit 2f5bdf9

Please sign in to comment.