pub trait Job:
Serialize
+ DeserializeOwned
+ Send
+ Sync
+ 'static {
const KIND: &'static str;
const MAX_ATTEMPTS: u32 = 8;
const TIMEOUT: Duration = _;
// Required method
fn run(self, cx: &Cx) -> impl Future<Output = Result<()>> + Send;
// Provided method
fn lane(&self) -> Option<String> { ... }
}Expand description
A kind of background work, whose fields are its payload.
use serde::{Deserialize, Serialize};
use tablo_jobs::Job;
use topcoat::context::Cx;
#[derive(Serialize, Deserialize)]
struct SyncSeats {
team: u64,
}
impl Job for SyncSeats {
const KIND: &'static str = "sync-seats";
fn lane(&self) -> Option<String> {
Some(format!("team:{}", self.team))
}
async fn run(self, cx: &Cx) -> topcoat::Result<()> {
// Read the team as it is now, and push its seat count.
Ok(())
}
}runmay run twice for one enqueue, after a crash or a lapsed lock, so it is idempotent.- It reads the world as it is when it runs, not as it was at enqueue: the payload names rows, it does not copy them.
- The payload lives in the database and its backups in clear: it carries no secret.
- A run past
TIMEOUTis dropped at its next.await. A run that blocks its thread instead outlives its lock, and another worker starts it again beside it: blocking work goes throughtokio::task::spawn_blocking.
Required Associated Constants§
Provided Associated Constants§
Sourceconst MAX_ATTEMPTS: u32 = 8
const MAX_ATTEMPTS: u32 = 8
How many runs it gets before it turns Dead.
Required Methods§
Sourcefn run(self, cx: &Cx) -> impl Future<Output = Result<()>> + Send
fn run(self, cx: &Cx) -> impl Future<Output = Result<()>> + Send
Does the work, reading what it needs from cx: the context
PanelHandle::context builds, with what
Worker::context adds. An error retries it with backoff until
it has spent its attempts.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".