class MotherBrain::JobManager

Attributes

list[R]

@return [Set<JobRecord>]

listing of records of all jobs; completed and active
records[R]

@return [Set<JobRecord>]

listing of records of all jobs; completed and active

Public Class Methods

instance() click to toggle source

@raise [Celluloid::DeadActorError] if job manager has not been started

@return [Celluloid::Actor(JobManager)]

# File lib/mb/job_manager.rb, line 7
def instance
  MB::Application[:job_manager] or raise Celluloid::DeadActorError, "job manager not running"
end
new() click to toggle source
# File lib/mb/job_manager.rb, line 32
def initialize
  log.debug { "Job Manager starting..." }
  @records = Set.new
  @_active = Set.new
end
running?() click to toggle source
# File lib/mb/job_manager.rb, line 11
def running?
  MB::Application[:job_manager] && instance.alive?
end
stopped?() click to toggle source
# File lib/mb/job_manager.rb, line 15
def stopped?
  !running?
end

Public Instance Methods

active() click to toggle source

listing of all active jobs

@return [Set<JobRecord>]

# 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) click to toggle source

Track and record the given job

@param [Job] job

# 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) click to toggle source

Complete the given active job

@param [Job] job

# File lib/mb/job_manager.rb, line 50
def complete_job(job)
  @_active.delete(job)
end
find(id) click to toggle source

@param [String] id

# File lib/mb/job_manager.rb, line 63
def find(id)
  records.find { |record| record.id == id }
end
terminate_active() click to toggle source
# File lib/mb/job_manager.rb, line 74
def terminate_active
  @_active.map { |job| job.terminate if job.alive? }
end
update(job) click to toggle source

Update the record for the given Job

@param [Job] job

# File lib/mb/job_manager.rb, line 70
def update(job)
  find(job.id).update(job)
end
uuid() click to toggle source

Generate a new Job ID

@return [String]

# File lib/mb/job_manager.rb, line 81
def uuid
  Celluloid::UUID.generate
end

Private Instance Methods

finalize_callback() click to toggle source
# File lib/mb/job_manager.rb, line 87
def finalize_callback
  log.debug { "Job Manager stopping..." }
  terminate_active
end
force_complete(actor, reason) click to toggle source
# File lib/mb/job_manager.rb, line 92
def force_complete(actor, reason)
  complete_job(actor)
end