Class: Sidekiq::SortedEntry
Overview
Represents a job within a Redis sorted set where the score represents a timestamp associated with the job. This timestamp could be the scheduled time for it to run (e.g. scheduled set), or the expiration date after which the entry should be deleted (e.g. dead set).
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
#Item, #Queue, #Value, #item, #queue, #value
Instance Method Summary collapse
-
#add_to_queue ⇒ Object
Enqueue this job from the scheduled or dead set so it will be executed at some point in the near future.
-
#at ⇒ Object
The timestamp associated with this entry.
-
#delete ⇒ Object
remove this entry from the sorted set.
- #error? ⇒ Boolean
-
#kill ⇒ Object
Move this job from its current set into the Dead set.
-
#reschedule(at) ⇒ Object
Change the scheduled time for this job.
-
#retry ⇒ Object
enqueue this job from the retry set so it will be executed at some point in the near future.
Methods inherited from JobRecord
#[], #args, #bid, #created_at, #display_args, #display_class, #enqueued_at, #error_backtrace, #jid, #klass, #latency, #tags
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
503 504 505 |
# File 'lib/sidekiq/api.rb', line 503 def parent @parent end |
#score ⇒ Object (readonly)
Returns the value of attribute score.
502 503 504 |
# File 'lib/sidekiq/api.rb', line 502 def score @score end |
Instance Method Details
#add_to_queue ⇒ Object
Enqueue this job from the scheduled or dead set so it will be executed at some point in the near future.
538 539 540 541 542 543 |
# File 'lib/sidekiq/api.rb', line 538 def add_to_queue remove_job do || msg = Sidekiq.load_json() Sidekiq::Client.push(msg) end end |
#at ⇒ Object
The timestamp associated with this entry
514 515 516 |
# File 'lib/sidekiq/api.rb', line 514 def at Time.at(score).utc end |
#delete ⇒ Object
remove this entry from the sorted set
519 520 521 522 523 524 525 |
# File 'lib/sidekiq/api.rb', line 519 def delete if @value @parent.delete_by_value(@parent.name, @value) else @parent.delete_by_jid(score, jid) end end |
#error? ⇒ Boolean
562 563 564 |
# File 'lib/sidekiq/api.rb', line 562 def error? !!item["error_class"] end |
#kill ⇒ Object
Move this job from its current set into the Dead set.
556 557 558 559 560 |
# File 'lib/sidekiq/api.rb', line 556 def kill remove_job do || DeadSet.new.kill() end end |
#reschedule(at) ⇒ Object
Change the scheduled time for this job.
530 531 532 533 534 |
# File 'lib/sidekiq/api.rb', line 530 def reschedule(at) Sidekiq.redis do |conn| conn.zincrby(@parent.name, at.to_f - @score, Sidekiq.dump_json(@item)) end end |
#retry ⇒ Object
enqueue this job from the retry set so it will be executed at some point in the near future.
547 548 549 550 551 552 553 |
# File 'lib/sidekiq/api.rb', line 547 def retry remove_job do || msg = Sidekiq.load_json() msg["retry_count"] -= 1 if msg["retry_count"] Sidekiq::Client.push(msg) end end |