Class: MotherBrain::JobManager

Inherits:
Object
  • Object
show all
Includes:
Celluloid, Logging
Defined in:
lib/mb/job_manager.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

add_argument_header, dev, filename, #log_exception, logger, #logger, reset, set_logger, setup

Constructor Details

#initializeJobManager

Returns a new instance of JobManager.



32
33
34
35
36
# File 'lib/mb/job_manager.rb', line 32

def initialize
  log.debug { "Job Manager starting..." }
  @records = Set.new
  @_active = Set.new
end

Instance Attribute Details

#recordsSet<JobRecord> (readonly) Also known as: list

Returns listing of records of all jobs; completed and active.

Returns:

  • (Set<JobRecord>)

    listing of records of all jobs; completed and active



27
28
29
# File 'lib/mb/job_manager.rb', line 27

def records
  @records
end

Class Method Details

.instanceCelluloid::Actor(JobManager)

Returns:

Raises:

  • (Celluloid::DeadActorError)

    if job manager has not been started



7
8
9
# File 'lib/mb/job_manager.rb', line 7

def instance
  MB::Application[:job_manager] or raise Celluloid::DeadActorError, "job manager not running"
end

.running?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/mb/job_manager.rb', line 11

def running?
  MB::Application[:job_manager] && instance.alive?
end

.stopped?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/mb/job_manager.rb', line 15

def stopped?
  !running?
end

Instance Method Details

#activeSet<JobRecord>

listing of all active jobs

Returns:



57
58
59
60
# File 'lib/mb/job_manager.rb', line 57

def active
  active_ids = @_active.collect {|j| j.id }
  records.select {|r| active_ids.include?(r.id) }
end

#add(job) ⇒ Object

Track and record the given job

Parameters:



41
42
43
44
45
# File 'lib/mb/job_manager.rb', line 41

def add(job)
  @_active.add(job)
  records.add JobRecord.new(job)
  monitor(job)
end

#complete_job(job) ⇒ Object

Complete the given active job

Parameters:



50
51
52
# File 'lib/mb/job_manager.rb', line 50

def complete_job(job)
  @_active.delete(job)
end

#find(id) ⇒ Object

Parameters:

  • id (String)


63
64
65
# File 'lib/mb/job_manager.rb', line 63

def find(id)
  records.find { |record| record.id == id }
end

#terminate_activeObject



74
75
76
# File 'lib/mb/job_manager.rb', line 74

def terminate_active
  @_active.map { |job| job.terminate if job.alive? }
end

#update(job) ⇒ Object

Update the record for the given Job

Parameters:



70
71
72
# File 'lib/mb/job_manager.rb', line 70

def update(job)
  find(job.id).update(job)
end

#uuidString

Generate a new Job ID

Returns:

  • (String)


81
82
83
# File 'lib/mb/job_manager.rb', line 81

def uuid
  Celluloid::UUID.generate
end