Class: Rector::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/rector/job.rb

Defined Under Namespace

Classes: WorkerCollection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeJob

Returns a new instance of Job.



23
24
25
26
# File 'lib/rector/job.rb', line 23

def initialize
  @workers = WorkerCollection.new(self)
  @backend = Rector.backend_for(id)
end

Instance Attribute Details

#workersObject (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_idObject



34
35
36
37
38
# File 'lib/rector/job.rb', line 34

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

#cleanupObject



50
51
52
# File 'lib/rector/job.rb', line 50

def cleanup
  @backend.cleanup
end

#dataObject



46
47
48
# File 'lib/rector/job.rb', line 46

def data
  @data ||= @backend.read_job_data_to_hash
end

#idObject



28
29
30
31
32
# File 'lib/rector/job.rb', line 28

def id
  # TODO: Obviously there's a small chance of jobs overlapping here
  # Can do something more reliable for ID generation?
  @id ||= SecureRandom.hex(10)
end

#joinObject



40
41
42
43
44
# File 'lib/rector/job.rb', line 40

def join
  while @backend.workers_working?
    sleep 5
  end
end