module

JoobQ::InFlight

The jobs this process has claimed and not finished, with the queue each came from, so JoobQ.shutdown can let them finish and, at its deadline, put the rest back on their queues.

A claim is identified by a token, not by the job's raw string (two claims of the same string must not collide). It is claimed from the moment its worker got the job from Redis (before any fiber exists for it), running once its fiber began, settling while the fiber applies the outcome of a failure (scheduling a retry, dead-lettering) and abandoned when shutdown gave up on it and returned it to its queue.

An abandoned execution must be inert: its fiber must not start the job (if it has not yet), must not touch the processing list when it ends (another process may have claimed the job since), and none of its failure or success handling may schedule, dead-letter, count or announce anything, because the requeued copy owns the job now. The handling asks settle before its first side effect: the answer and the move to settling are one step under the lock, so shutdown either abandoned the job before (the handling does nothing) or finds it settling and waits for it instead of requeuing it while a retry is being scheduled.

Class methods

abandon_all(settling : Bool = false) : Array(Tuple(String, String))

Marks the claimed and running jobs abandoned and returns them as {queue, job}. Jobs that are settling are left alone (they are applying a failure outcome and finish in a moment), unless settling is true: the last resort at the deadline, when their side effects may already be done.

Source
abandoned?

Whether the job being executed by the current fiber was abandoned by shutdown. Read only, and cheap enough for the hot path: false without taking a lock until some job has been abandoned.

Source
after_settle

Specs only: called, outside the lock, right after a fiber moved to settling.

Source
after_settle=(after_settle : Proc(Nil) | Nil)

Specs only: called, outside the lock, right after a fiber moved to settling.

Source
begin_run(token : Int64) : Bool

The claim's fiber begins (the current fiber is remembered for settle and abandoned?). False when shutdown abandoned the claim first: do not run the job.

Source
claimed(queue : String, jobs : Array(String)) : Array(Int64)

Registers freshly claimed jobs, one token each in the order given. Call it as soon as the claim returns.

Source
clear

Specs only: forgets everything.

Source
count

Jobs claimed, running or settling (abandoned ones are not counted).

Source
finished(token : Int64) : Bool

The claim's fiber ends. True when shutdown had abandoned it (the job is already back on its queue: leave the processing list alone).

Source
settle

Called by the failure handling of the current fiber's job before its first side effect. True: go ahead (the job is now settling, shutdown waits for it rather than abandoning it). False: shutdown abandoned this execution, so do nothing. True as well for a fiber that is not running a claimed job.

Source
wait(timeout : Time::Span) : Bool

Waits until no job is claimed, running or settling, or timeout passes. True when the process went quiet.

Source

Nested types