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

#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

#idObject (readonly)

Returns the value of attribute id.



21
22
23
# File 'lib/rector/job.rb', line 21

def id
  @id
end

#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



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

#cleanupObject



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

def cleanup
  @backend.cleanup
end

#dataObject



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

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

#joinObject



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_workingObject



43
44
45
# File 'lib/rector/job.rb', line 43

def num_workers_working
  @backend.num_workers_working
end