pub struct JobContext {
pub job_id: Uuid,
pub job_type: String,
pub attempt: u32,
pub max_attempts: u32,
pub auth: AuthContext,
/* private fields */
}Expand description
Context available to job handlers.
Fields§
§job_id: UuidJob ID.
job_type: StringJob type/name.
attempt: u32Current attempt number (1-based).
max_attempts: u32Maximum attempts allowed.
auth: AuthContextAuthentication context (for queries/mutations).
Implementations§
Source§impl JobContext
impl JobContext
Sourcepub fn new(
job_id: Uuid,
job_type: String,
attempt: u32,
max_attempts: u32,
db_pool: PgPool,
http_client: Client,
) -> Self
pub fn new( job_id: Uuid, job_type: String, attempt: u32, max_attempts: u32, db_pool: PgPool, http_client: Client, ) -> Self
Create a new job context.
Sourcepub fn with_saved(self, data: Value) -> Self
pub fn with_saved(self, data: Value) -> Self
Create a new job context with persisted saved data.
Sourcepub fn with_auth(self, auth: AuthContext) -> Self
pub fn with_auth(self, auth: AuthContext) -> Self
Set authentication context.
Sourcepub fn with_progress(self, tx: Sender<ProgressUpdate>) -> Self
pub fn with_progress(self, tx: Sender<ProgressUpdate>) -> Self
Set progress channel.
Sourcepub fn with_env_provider(self, provider: Arc<dyn EnvProvider>) -> Self
pub fn with_env_provider(self, provider: Arc<dyn EnvProvider>) -> Self
Set environment provider.
Sourcepub fn progress(&self, percentage: u8, message: impl Into<String>) -> Result<()>
pub fn progress(&self, percentage: u8, message: impl Into<String>) -> Result<()>
Report job progress.
Sourcepub async fn saved(&self) -> Value
pub async fn saved(&self) -> Value
Get all saved job data.
Returns data that was saved during job execution via save().
This data persists across retries and is accessible in compensation handlers.
Sourcepub async fn set_saved(&self, data: Value) -> Result<()>
pub async fn set_saved(&self, data: Value) -> Result<()>
Replace all saved job data.
Replaces the entire saved data object. For updating individual keys,
use save() instead.
Sourcepub async fn save(&self, key: &str, value: Value) -> Result<()>
pub async fn save(&self, key: &str, value: Value) -> Result<()>
Save a key-value pair to persistent job data.
Saved data persists across retries and is accessible in compensation handlers. Use this to store information needed for rollback (e.g., transaction IDs, resource handles, progress markers).
§Example
ctx.save("charge_id", json!(charge.id)).await?;
ctx.save("refund_amount", json!(amount)).await?;Sourcepub async fn is_cancel_requested(&self) -> Result<bool>
pub async fn is_cancel_requested(&self) -> Result<bool>
Check if cancellation has been requested for this job.
Sourcepub async fn check_cancelled(&self) -> Result<()>
pub async fn check_cancelled(&self) -> Result<()>
Return an error if cancellation has been requested.
Sourcepub fn is_last_attempt(&self) -> bool
pub fn is_last_attempt(&self) -> bool
Check if this is the last attempt.
Trait Implementations§
Source§impl EnvAccess for JobContext
impl EnvAccess for JobContext
Source§fn env_provider(&self) -> &dyn EnvProvider
fn env_provider(&self) -> &dyn EnvProvider
Source§fn env_or(&self, key: &str, default: &str) -> String
fn env_or(&self, key: &str, default: &str) -> String
Source§fn env_require(&self, key: &str) -> Result<String>
fn env_require(&self, key: &str) -> Result<String>
Source§fn env_parse<T: FromStr>(&self, key: &str) -> Result<T>
fn env_parse<T: FromStr>(&self, key: &str) -> Result<T>
Source§fn env_parse_or<T: FromStr>(&self, key: &str, default: T) -> Result<T>
fn env_parse_or<T: FromStr>(&self, key: &str, default: T) -> Result<T>
Source§fn env_contains(&self, key: &str) -> bool
fn env_contains(&self, key: &str) -> bool
Auto Trait Implementations§
impl Freeze for JobContext
impl !RefUnwindSafe for JobContext
impl Send for JobContext
impl Sync for JobContext
impl Unpin 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> 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