Class: Rector::Job
- Inherits:
-
Object
show all
- Defined in:
- lib/rector/job.rb
Defined Under Namespace
Classes: WorkerCollection
Instance Attribute Summary collapse
Instance Method Summary
collapse
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?
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
21
22
23
|
# File 'lib/rector/job.rb', line 21
def id
@id
end
|
#workers ⇒ Object
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
"#{id}:#{SecureRandom.hex(8)}"
end
|
#cleanup ⇒ Object
51
52
53
|
# File 'lib/rector/job.rb', line 51
def cleanup
@backend.cleanup
end
|
#data ⇒ Object
47
48
49
|
# File 'lib/rector/job.rb', line 47
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 num_workers_working > 0
sleep 5
end
end
|
#num_workers_working ⇒ Object
43
44
45
|
# File 'lib/rector/job.rb', line 43
def num_workers_working
@backend.num_workers_working
end
|