Module: RoundhouseUi::Cancellation
- Defined in:
- lib/roundhouse_ui/cancellation.rb
Overview
Cooperative job cancellation — pure OSS, no preemption (Ruby can't safely kill a running thread). Cancelled JIDs live in a Redis set:
* RoundhouseUi::CancelMiddleware skips a job whose JID is cancelled when it
is *about* to run (covers queued/scheduled/retry jobs).
* A long-running job can call RoundhouseUi.cancelled?(jid) and bail out.
The set expires so stale flags clean themselves up.
Constant Summary collapse
- KEY =
"roundhouse:cancelled"- TTL =
seconds
86_400
Class Method Summary collapse
Class Method Details
.cancel!(jid) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/roundhouse_ui/cancellation.rb', line 18 def cancel!(jid) Sidekiq.redis do |conn| conn.call("SADD", KEY, jid.to_s) conn.call("EXPIRE", KEY, TTL) end end |
.cancelled?(jid) ⇒ Boolean
25 26 27 |
# File 'lib/roundhouse_ui/cancellation.rb', line 25 def cancelled?(jid) Sidekiq.redis { |conn| conn.call("SISMEMBER", KEY, jid.to_s) } == 1 end |
.cancelled_jids ⇒ Object
33 34 35 |
# File 'lib/roundhouse_ui/cancellation.rb', line 33 def cancelled_jids Sidekiq.redis { |conn| conn.call("SMEMBERS", KEY) } end |
.clear!(jid) ⇒ Object
29 30 31 |
# File 'lib/roundhouse_ui/cancellation.rb', line 29 def clear!(jid) Sidekiq.redis { |conn| conn.call("SREM", KEY, jid.to_s) } end |