Class: Fractor::PriorityWork
Overview
PriorityWork extends Work with priority levels for priority-based scheduling
Priority levels:
- :critical - Highest priority, processed first
- :high - High priority
- :normal - Default priority (backward compatible)
- :low - Low priority
- :background - Lowest priority
Constant Summary collapse
- PRIORITY_LEVELS =
{ critical: 0, high: 1, normal: 2, low: 3, background: 4, }.freeze
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
Attributes inherited from Work
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer
Compare priorities for sorting Lower priority value = higher priority For same priority, older work comes first (FIFO within priority).
-
#age ⇒ Float
Calculate age in seconds (used for priority aging).
-
#higher_priority_than?(other) ⇒ Boolean
Check if this work has higher priority than another.
-
#initialize(input, priority: :normal) ⇒ PriorityWork
constructor
Initialize a new PriorityWork.
-
#priority_value ⇒ Integer
Get numeric priority value (lower is higher priority).
Methods inherited from Work
Constructor Details
#initialize(input, priority: :normal) ⇒ PriorityWork
Initialize a new PriorityWork
35 36 37 38 39 40 |
# File 'lib/fractor/priority_work.rb', line 35 def initialize(input, priority: :normal) super(input) validate_priority!(priority) @priority = priority @created_at = Time.now end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
28 29 30 |
# File 'lib/fractor/priority_work.rb', line 28 def created_at @created_at end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
28 29 30 |
# File 'lib/fractor/priority_work.rb', line 28 def priority @priority end |
Instance Method Details
#<=>(other) ⇒ Integer
Compare priorities for sorting Lower priority value = higher priority For same priority, older work comes first (FIFO within priority)
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/fractor/priority_work.rb', line 62 def <=>(other) return nil unless other.is_a?(PriorityWork) # First compare by priority value result = priority_value <=> other.priority_value return result unless result.zero? # If same priority, use FIFO (older first) created_at <=> other.created_at end |
#age ⇒ Float
Calculate age in seconds (used for priority aging)
52 53 54 |
# File 'lib/fractor/priority_work.rb', line 52 def age Time.now - @created_at end |
#higher_priority_than?(other) ⇒ Boolean
Check if this work has higher priority than another
77 78 79 80 81 |
# File 'lib/fractor/priority_work.rb', line 77 def higher_priority_than?(other) return false unless other.is_a?(PriorityWork) priority_value < other.priority_value end |
#priority_value ⇒ Integer
Get numeric priority value (lower is higher priority)
45 46 47 |
# File 'lib/fractor/priority_work.rb', line 45 def priority_value PRIORITY_LEVELS[@priority] end |