struct
Amber::Jobs::JobEnvelope
- Amber::Jobs::JobEnvelope
- Struct
- Value
- Object
Overview
Wraps a job with metadata for queue management.
A JobEnvelope carries all the information needed to track, schedule, retry, and execute a job within the background processing system. It acts as the transport container that moves through the queue adapter, worker, and scheduler.
Fields
#id- A unique UUID identifying this job instance#job_class- The fully qualified Crystal class name for deserialization#payload- JSON-serialized job data (constructor arguments)#queue- The queue this job belongs to (e.g., "default", "critical")#attempts- How many times this job has been attempted#max_retries- Maximum number of retry attempts before the job is marked dead#scheduled_at- When the job should be executed (supports delayed execution)#created_at- When the job was originally enqueued#status- Current lifecycle status of the job#last_error- The error message from the most recent failed attempt, if any
Included Modules
- JSON::Serializable
Defined in:
amber/jobs/job_envelope.crConstructors
- .new(job_class : String, payload : String, queue : String = "default", max_retries : Int32 = 3, scheduled_at : Time = Time.utc, status : Status = Status::Pending)
- .new(pull : JSON::PullParser)
Instance Method Summary
- #attempts : Int32
- #attempts=(attempts : Int32)
- #created_at : Time
- #created_at=(created_at : Time)
-
#has_exceeded_max_retries? : Bool
Returns true if the job has exceeded its maximum retry attempts.
- #id : String
- #id=(id : String)
-
#is_ready_to_run? : Bool
Returns true if the job is ready to be executed based on its scheduled time.
- #job_class : String
- #job_class=(job_class : String)
- #last_error : String | Nil
- #last_error=(last_error : String | Nil)
-
#mark_as_completed : Nil
Sets the status to Completed.
-
#mark_as_dead(error : String) : Nil
Sets the status to Dead (exceeded max retries, will not be retried).
-
#mark_as_failed(error : String) : Nil
Sets the status to Failed with an error message.
-
#mark_as_running : Nil
Increments the attempt counter and sets the status to Running.
- #max_retries : Int32
- #max_retries=(max_retries : Int32)
- #payload : String
- #payload=(payload : String)
- #queue : String
- #queue=(queue : String)
-
#schedule_retry(backoff : Time::Span) : Nil
Resets the status to Pending for retry, updating the scheduled time based on exponential backoff.
- #scheduled_at : Time
- #scheduled_at=(scheduled_at : Time)
- #status : Status
- #status=(status : Status)
Constructor Detail
Instance Method Detail
Returns true if the job has exceeded its maximum retry attempts.
Returns true if the job is ready to be executed based on its scheduled time.
Sets the status to Dead (exceeded max retries, will not be retried).
Sets the status to Failed with an error message.
Resets the status to Pending for retry, updating the scheduled time based on exponential backoff.