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.
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
- #id ⇒ Object
-
#initialize(parent, score, item) ⇒ SortedEntry
constructor
private
:nodoc:.
-
#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.
- #score ⇒ Object
Methods inherited from JobRecord
#[], #args, #bid, #created_at, #display_args, #display_class, #enqueued_at, #error_backtrace, #failed_at, #iterable_state, #jid, #klass, #latency, #parse, #retried_at, #tags
Methods included from ApiUtils
Constructor Details
#initialize(parent, score, item) ⇒ SortedEntry
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
:nodoc:
595 596 597 598 599 |
# File 'lib/sidekiq/api.rb', line 595 def initialize(parent, score, item) super(item) @score = score @parent = parent end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
591 592 593 |
# File 'lib/sidekiq/api.rb', line 591 def parent @parent 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.
634 635 636 637 638 639 |
# File 'lib/sidekiq/api.rb', line 634 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
610 611 612 |
# File 'lib/sidekiq/api.rb', line 610 def at Time.at(score).utc end |
#delete ⇒ Object
remove this entry from the sorted set
615 616 617 618 619 620 621 |
# File 'lib/sidekiq/api.rb', line 615 def delete if @value @parent.delete_by_value(@parent.name, @value) else @parent.delete_by_jid(@score, jid) end end |
#error? ⇒ Boolean
658 659 660 |
# File 'lib/sidekiq/api.rb', line 658 def error? !!item["error_class"] end |
#id ⇒ Object
605 606 607 |
# File 'lib/sidekiq/api.rb', line 605 def id "#{@score}|#{item["jid"]}" end |
#kill ⇒ Object
Move this job from its current set into the Dead set.
652 653 654 655 656 |
# File 'lib/sidekiq/api.rb', line 652 def kill remove_job do || DeadSet.new.kill() end end |
#reschedule(at) ⇒ Object
Change the scheduled time for this job.
626 627 628 629 630 |
# File 'lib/sidekiq/api.rb', line 626 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.
643 644 645 646 647 648 649 |
# File 'lib/sidekiq/api.rb', line 643 def retry remove_job do || msg = Sidekiq.load_json() msg["retry_count"] -= 1 if msg["retry_count"] Sidekiq::Client.push(msg) end end |
#score ⇒ Object
601 602 603 |
# File 'lib/sidekiq/api.rb', line 601 def score Float(@score) end |