Class: Rector::Job
- Inherits:
-
Object
- Object
- Rector::Job
- Defined in:
- lib/rector/job.rb
Defined Under Namespace
Classes: WorkerCollection
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#workers ⇒ Object
readonly
Returns the value of attribute workers.
Instance Method Summary collapse
- #allocate_worker_id ⇒ Object
- #cleanup ⇒ Object
- #data ⇒ Object
-
#initialize(id = SecureRandom.hex(10)) ⇒ Job
constructor
TODO: Obviously there’s a small chance of jobs overlapping here Can do something more reliable for ID generation?.
- #join ⇒ Object
Constructor Details
#initialize(id = SecureRandom.hex(10)) ⇒ Job
TODO: Obviously there’s a small chance of jobs overlapping here Can do something more reliable for ID generation?
25 26 27 28 29 |
# File 'lib/rector/job.rb', line 25 def initialize(id = SecureRandom.hex(10)) @id = id @workers = WorkerCollection.new(self) @backend = Rector.backend_for(id) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
21 22 23 |
# File 'lib/rector/job.rb', line 21 def id @id end |
#workers ⇒ Object (readonly)
Returns the value of attribute workers.
21 22 23 |
# File 'lib/rector/job.rb', line 21 def workers @workers end |
Instance Method Details
#allocate_worker_id ⇒ Object
31 32 33 34 35 |
# File 'lib/rector/job.rb', line 31 def allocate_worker_id # TODO: Obviously there's a small chance of jobs overlapping here # Can do something more reliable for ID generation? "#{id}:#{SecureRandom.hex(8)}" end |
#cleanup ⇒ Object
47 48 49 |
# File 'lib/rector/job.rb', line 47 def cleanup @backend.cleanup end |
#data ⇒ Object
43 44 45 |
# File 'lib/rector/job.rb', line 43 def data @data ||= @backend.read_job_data_to_hash end |
#join ⇒ Object
37 38 39 40 41 |
# File 'lib/rector/job.rb', line 37 def join while @backend.workers_working? sleep 5 end end |