Skip to content
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Unreleased
- Feat: Worker::perform_later() now returns job IDs for status tracking. Returns `Result<Option<String>>` with the job ID when using background queue mode. [https://github.com/loco-rs/loco/issues/1623](https://github.com/loco-rs/loco/issues/1623)

## v0.16.4
- Feat: decouple JWT authentication from database dependency. [https://github.com/loco-rs/loco/pull/1546](https://github.com/loco-rs/loco/pull/1546)
Expand Down
12 changes: 9 additions & 3 deletions docs-site/content/docs/processing/workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,19 @@ To use a worker, we mainly think about adding a job to the queue, so you `use` t

```rust
// .. in your controller ..
DownloadWorker::perform_later(
let job_id = DownloadWorker::perform_later(
&ctx,
DownloadWorkerArgs {
user_guid: "foo".to_string(),
},
)
.await
.await?;

// The job ID can be used for tracking job status
if let Some(id) = job_id {
println!("Job queued with ID: {}", id);
// You can store this ID to check job status later
}
```

Unlike Rails and Ruby, with Rust you can enjoy _strongly typed_ job arguments which gets serialized and pushed into the queue.
Expand Down Expand Up @@ -231,7 +237,7 @@ The `BackgroundWorker` trait is the core interface for defining background worke
- `queue() -> Option<String>`: Optional method to specify a custom queue for the worker (returns `None` by default).
- `tags() -> Vec<String>`: Optional method to specify tags for this worker (returns an empty vector by default).
- `class_name() -> String`: Returns the worker's class name (automatically derived from the struct name).
- `perform_later(ctx: &AppContext, args: A) -> Result<()>`: Static method to enqueue a job to be performed later.
- `perform_later(ctx: &AppContext, args: A) -> Result<Option<String>>`: Static method to enqueue a job to be performed later. Returns `Some(job_id)` when using background queue mode with a provider, `None` otherwise.

### Generate a Worker

Expand Down
Loading
Loading