Class: Wurk::SortedEntry
- Defined in:
- lib/wurk/sorted_entry.rb
Overview
One entry inside a sorted-set view (Retry/Scheduled/Dead). Carries the member’s ‘score` alongside the JobRecord so callers can re-target the exact (score, value) pair when mutating Redis — sorted-set membership is by value, but ZREM-by-value is faster than ZRANGEBYSCORE+filter.
The ‘id` field (“<score>|<jid>”) is the Sidekiq wire-compat identifier used by dashboards and third-party tooling. Don’t reformat it.
Spec: docs/target/sidekiq-free.md §19.4.
Constant Summary
Constants inherited from JobRecord
JobRecord::ACTION_MAILER_JOBS, JobRecord::ACTIVE_JOB_WRAPPER
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#score ⇒ Object
readonly
Returns the value of attribute score.
Attributes inherited from JobRecord
Instance Method Summary collapse
-
#add_to_queue ⇒ Object
Removes this entry, decrements ‘retry_count` by one (so the worker treats the next attempt as a re-do, not a fresh retry), and re-enqueues via the client.
- #at ⇒ Object
-
#delete ⇒ Object
Removes this entry from the parent set.
- #error? ⇒ Boolean
- #id ⇒ Object
-
#initialize(parent, score, item) ⇒ SortedEntry
constructor
A new instance of SortedEntry.
-
#kill ⇒ Object
Removes this entry from its parent set and writes it to the dead set.
-
#reschedule(at) ⇒ Object
ZINCRBY to shift the score; positive deltas reschedule into the future.
-
#retry ⇒ Object
Same flow as add_to_queue but keeps ‘retry_count` intact.
Methods inherited from JobRecord
#[], #args, #bid, #created_at, #display_args, #display_class, #enqueued_at, #error_backtrace, #failed_at, #item, #jid, #klass, #latency, latency_from, #retried_at, #tags, #value
Constructor Details
#initialize(parent, score, item) ⇒ SortedEntry
Returns a new instance of SortedEntry.
21 22 23 24 25 |
# File 'lib/wurk/sorted_entry.rb', line 21 def initialize(parent, score, item) super(item) @score = score.to_f @parent = parent end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
16 17 18 |
# File 'lib/wurk/sorted_entry.rb', line 16 def parent @parent end |
#score ⇒ Object (readonly)
Returns the value of attribute score.
16 17 18 |
# File 'lib/wurk/sorted_entry.rb', line 16 def score @score end |
Instance Method Details
#add_to_queue ⇒ Object
Removes this entry, decrements ‘retry_count` by one (so the worker treats the next attempt as a re-do, not a fresh retry), and re-enqueues via the client. Wire-compat with Sidekiq’s “Retry now” UI action.
52 53 54 55 56 57 |
# File 'lib/wurk/sorted_entry.rb', line 52 def add_to_queue remove_job do || ['retry_count'] = ['retry_count'].to_i - 1 if ['retry_count'] Client.new.push() end end |
#at ⇒ Object
29 |
# File 'lib/wurk/sorted_entry.rb', line 29 def at = ::Time.at(score).utc |
#delete ⇒ Object
Removes this entry from the parent set. Prefers exact-value match (idempotent across duplicates with the same jid), falls back to (score, jid) when constructed without a cached ‘value`.
34 35 36 37 38 39 40 |
# File 'lib/wurk/sorted_entry.rb', line 34 def delete if @value @parent.delete_by_value(@parent.name, @value) else @parent.delete_by_jid(@score, jid) end end |
#error? ⇒ Boolean
77 |
# File 'lib/wurk/sorted_entry.rb', line 77 def error? = !item['error_class'].nil? |
#id ⇒ Object
27 |
# File 'lib/wurk/sorted_entry.rb', line 27 def id = "#{score}|#{jid}" |
#kill ⇒ Object
Removes this entry from its parent set and writes it to the dead set. ‘notify_failure: false` because the kill is user-initiated (UI action), not a retry-exhausted event — death_handlers don’t fire.
71 72 73 74 75 |
# File 'lib/wurk/sorted_entry.rb', line 71 def kill remove_job do || DeadSet.new.kill(Wurk.dump_json(), notify_failure: false) end end |
#reschedule(at) ⇒ Object
ZINCRBY to shift the score; positive deltas reschedule into the future. Sidekiq passes the absolute target time; we compute the delta here so the call survives clock skew between caller and Redis.
45 46 47 |
# File 'lib/wurk/sorted_entry.rb', line 45 def reschedule(at) # rubocop:disable Naming/MethodParameterName Wurk.redis { |conn| conn.call('ZINCRBY', @parent.name, at.to_f - @score, value) } end |
#retry ⇒ Object
Same flow as add_to_queue but keeps ‘retry_count` intact. Used for the “retry” action from the retry set (count was already incremented when the job entered retry; don’t double-bump).
62 63 64 65 66 |
# File 'lib/wurk/sorted_entry.rb', line 62 def retry remove_job do || Client.new.push() end end |