class
Amber::Jobs::Worker
- Amber::Jobs::Worker
- Reference
- Object
Overview
Executes background jobs by polling the queue adapter.
A Worker runs in a background fiber, repeatedly checking configured queues for available jobs. When a job is found, it deserializes and executes it, handling retries and dead job marking on failure.
Usage
worker = Amber::Jobs::Worker.new(
adapter: Amber::Jobs.adapter,
list_of_queues: ["default", "critical"],
polling_interval: 1.second
)
worker.start
Work Stealing
When idle_only is set to true, the worker will only process jobs when
there are no pending HTTP requests. This allows idle web server instances
to contribute to job processing without impacting request latency.
Defined in:
amber/jobs/worker.crConstant Summary
-
Log =
::Log.for(self)
Constructors
Class Method Summary
-
.pending_request_count : Int64
Tracks pending HTTP request count for work-stealing mode.
-
.pending_request_count=(pending_request_count : Int64)
Tracks pending HTTP request count for work-stealing mode.
- .pending_request_mutex : Mutex
- .pending_request_mutex=(pending_request_mutex : Mutex)
Instance Method Summary
- #adapter : QueueAdapter
- #idle_only? : Bool
- #is_running? : Bool
- #jobs_processed : Int64
- #list_of_queues : Array(String)
- #polling_interval : Time::Span
-
#process_next_job : Bool
Attempts to dequeue and execute a single job from the configured queues.
-
#start : Nil
Starts the worker in a background fiber.
-
#stop : Nil
Stops the worker.
Constructor Detail
Class Method Detail
Tracks pending HTTP request count for work-stealing mode. This is incremented/decremented by the HTTP server middleware.
Tracks pending HTTP request count for work-stealing mode. This is incremented/decremented by the HTTP server middleware.
Instance Method Detail
Attempts to dequeue and execute a single job from the configured queues.
This method is exposed publicly for testing purposes.
Starts the worker in a background fiber.
The worker will poll all configured queues in order, executing any available jobs. This is a no-op if the worker is already running.
Stops the worker.
The worker will finish processing its current job (if any), complete its current sleep cycle, and then stop.