Class: Que::Metajob
- Inherits:
-
Object
- Object
- Que::Metajob
- Defined in:
- lib/que/metajob.rb
Constant Summary collapse
- SORT_KEYS =
[:priority, :run_at, :id].freeze
Instance Attribute Summary collapse
-
#job ⇒ Object
readonly
Returns the value of attribute job.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #id ⇒ Object
-
#initialize(job) ⇒ Metajob
constructor
A new instance of Metajob.
- #priority_sufficient?(threshold) ⇒ Boolean
- #set_job(job) ⇒ Object
Constructor Details
#initialize(job) ⇒ Metajob
Returns a new instance of Metajob.
12 13 14 |
# File 'lib/que/metajob.rb', line 12 def initialize(job) set_job(job) end |
Instance Attribute Details
#job ⇒ Object (readonly)
Returns the value of attribute job.
10 11 12 |
# File 'lib/que/metajob.rb', line 10 def job @job end |
Instance Method Details
#<=>(other) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/que/metajob.rb', line 28 def <=>(other) k1 = job k2 = other.job SORT_KEYS.each do |key| value1 = k1.fetch(key) value2 = k2.fetch(key) return -1 if value1 < value2 return 1 if value1 > value2 end 0 end |
#id ⇒ Object
24 25 26 |
# File 'lib/que/metajob.rb', line 24 def id job.fetch(:id) end |
#priority_sufficient?(threshold) ⇒ Boolean
43 44 45 |
# File 'lib/que/metajob.rb', line 43 def priority_sufficient?(threshold) threshold.nil? || job.fetch(:priority) <= threshold end |
#set_job(job) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/que/metajob.rb', line 16 def set_job(job) if (run_at = job.fetch(:run_at)).is_a?(Time) job[:run_at] = run_at.utc.iso8601(6) end @job = job end |