Class: MissionControl::Jobs::WorkersRelation
- Inherits:
-
Object
- Object
- MissionControl::Jobs::WorkersRelation
- Includes:
- Enumerable
- Defined in:
- lib/mission_control/jobs/workers_relation.rb
Overview
A relation of workers.
Relations are enumerable, so you can use Enumerable
methods on them. Notice however that using these methods will imply loading all the relation in memory, which could introduce performance concerns.
Constant Summary collapse
- ALL_WORKERS_LIMIT =
When no limit value it defaults to “all workers”
100_000_000
Instance Attribute Summary collapse
-
#limit_value ⇒ Object
Returns the value of attribute limit_value.
-
#offset_value ⇒ Object
Returns the value of attribute offset_value.
Instance Method Summary collapse
- #count ⇒ Object (also: #length, #size)
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(queue_adapter:) ⇒ WorkersRelation
constructor
A new instance of WorkersRelation.
- #limit(limit) ⇒ Object
- #offset(offset) ⇒ Object
- #reload ⇒ Object
Constructor Details
#initialize(queue_adapter:) ⇒ WorkersRelation
Returns a new instance of WorkersRelation.
15 16 17 18 19 |
# File 'lib/mission_control/jobs/workers_relation.rb', line 15 def initialize(queue_adapter:) @queue_adapter = queue_adapter set_defaults end |
Instance Attribute Details
#limit_value ⇒ Object
Returns the value of attribute limit_value.
9 10 11 |
# File 'lib/mission_control/jobs/workers_relation.rb', line 9 def limit_value @limit_value end |
#offset_value ⇒ Object
Returns the value of attribute offset_value.
9 10 11 |
# File 'lib/mission_control/jobs/workers_relation.rb', line 9 def offset_value @offset_value end |
Instance Method Details
#count ⇒ Object Also known as: length, size
38 39 40 41 42 43 44 |
# File 'lib/mission_control/jobs/workers_relation.rb', line 38 def count if loaded? to_a.length else query_count end end |
#each(&block) ⇒ Object
29 30 31 |
# File 'lib/mission_control/jobs/workers_relation.rb', line 29 def each(&block) workers.each(&block) end |
#empty? ⇒ Boolean
46 47 48 |
# File 'lib/mission_control/jobs/workers_relation.rb', line 46 def empty? count == 0 end |
#limit(limit) ⇒ Object
25 26 27 |
# File 'lib/mission_control/jobs/workers_relation.rb', line 25 def limit(limit) clone_with limit_value: limit end |
#offset(offset) ⇒ Object
21 22 23 |
# File 'lib/mission_control/jobs/workers_relation.rb', line 21 def offset(offset) clone_with offset_value: offset end |
#reload ⇒ Object
33 34 35 36 |
# File 'lib/mission_control/jobs/workers_relation.rb', line 33 def reload @count = @workers = nil self end |