Module: ActiveJob::Worker
- Defined in:
- runtime/active_job/worker.rbs,
runtime/active_job/worker.rb
Constant Summary collapse
- POLL_INTERVAL =
How often the drain loop looks for work, in seconds. A cooperative poll rather than a wakeup because there is nothing to wake on: the queue is a plain Array and an enqueue happens on another fiber inside the same process.
0.05
Class Method Summary collapse
-
.run ⇒ void
the drain loop: poll, run one drain, and repeat.
Class Method Details
.run ⇒ void
the drain loop: poll, run one drain, and repeat. The launcher spawns one
of these per worker thread; register_executor flips enqueue from
call-site execution to queueing, and this loop is what makes the queue
real. It executes one-off, delayed, and recurring jobs alike (the
scheduler only enqueues the last). WORKER_CONCURRENCY runs more side by
side — the adapter's claim is atomic so rows are split between them, but
the global FIFO order is only guaranteed at one. Each worker thread holds
its own Sqlx::Database lease, so DATABASE_POOL_SIZE must cover worker
threads plus request threads. The loop holds no queue knowledge: each
iteration asks whether a drain is due (drain_due? — the process queue is
due when work is waiting, the DB adapter samples its rows ~1s) and drains
through the same slot. A job runs outside any request's
Sqlx::Database.with_connection, so touching a model without one would
borrow whichever handle a request happened to be using. Nothing is retried
and nothing survives a restart on the process-local queue; the DB rows are
the restart-surviving half.
35 |
# File 'runtime/active_job/worker.rb', line 35
def self.run: () -> void
|