pub struct JobContext {
pub job: JobRow,
/* private fields */
}Expand description
Context passed to worker handlers during job execution.
Provides access to the job metadata, shared state (e.g., service dependencies), callback registration, and structured progress reporting.
Fields§
§job: JobRowThe raw job row from the database.
Implementations§
Source§impl JobContext
impl JobContext
pub fn new( job: JobRow, cancelled: Arc<AtomicBool>, state: Arc<HashMap<TypeId, Box<dyn Any + Send + Sync>>>, pool: PgPool, progress: Arc<Mutex<ProgressState>>, ) -> Self
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Check if this job’s execution has been cancelled (shutdown or deadline).
Sourcepub fn cancellation_flag(&self) -> Arc<AtomicBool> ⓘ
pub fn cancellation_flag(&self) -> Arc<AtomicBool> ⓘ
Clone the shared cancellation flag for language bridges.
Sourcepub fn extract<T: Any + Send + Sync + Clone>(&self) -> Option<T>
pub fn extract<T: Any + Send + Sync + Clone>(&self) -> Option<T>
Extract a shared state value by type.
State values are registered via Client::builder().state(value).
Sourcepub async fn register_callback(
&self,
timeout: Duration,
) -> Result<CallbackToken, AwaError>
pub async fn register_callback( &self, timeout: Duration, ) -> Result<CallbackToken, AwaError>
Register a callback for this job, writing the callback_id to the database immediately.
Call this BEFORE sending the callback_id to the external system to avoid the race condition where the external system fires before the DB knows about the callback.
Returns a CallbackToken whose id should be included in the URL or
payload sent to the external system.
Sourcepub async fn register_callback_with_config(
&self,
timeout: Duration,
config: &CallbackConfig,
) -> Result<CallbackToken, AwaError>
pub async fn register_callback_with_config( &self, timeout: Duration, config: &CallbackConfig, ) -> Result<CallbackToken, AwaError>
Register a callback with CEL expressions for automatic resolution.
See CallbackConfig for expression semantics.
Sourcepub fn set_progress(&self, percent: u8, message: Option<&str>)
pub fn set_progress(&self, percent: u8, message: Option<&str>)
Set structured progress (0-100, optional message). Sync — writes to in-memory buffer.
percent is clamped to 0-100.
Sourcepub fn update_metadata(&self, updates: Value) -> Result<(), AwaError>
pub fn update_metadata(&self, updates: Value) -> Result<(), AwaError>
Shallow-merge keys into progress.metadata for checkpointing. Sync.
updates must be a JSON object. Top-level keys overwrite; nested objects
are replaced, not deep-merged.
Sourcepub async fn flush_progress(&self) -> Result<(), AwaError>
pub async fn flush_progress(&self) -> Result<(), AwaError>
Force immediate flush of pending progress to DB. For critical checkpoints.
Does not return success until the progress has been durably written or the job is no longer in running state (rescued/cancelled).
Sourcepub fn progress_buffer(&self) -> Arc<Mutex<ProgressState>>
pub fn progress_buffer(&self) -> Arc<Mutex<ProgressState>>
Get a clone of the shared progress state Arc (for Python bridge).
Auto Trait Implementations§
impl Freeze for JobContext
impl !RefUnwindSafe for JobContext
impl Send for JobContext
impl Sync for JobContext
impl Unpin for JobContext
impl UnsafeUnpin for JobContext
impl !UnwindSafe for JobContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more