Class: MotherBrain::JobManager
- Inherits:
-
Object
- Object
- MotherBrain::JobManager
- Includes:
- Celluloid, Logging
- Defined in:
- lib/mb/job_manager.rb
Instance Attribute Summary collapse
-
#records ⇒ Set<JobRecord>
(also: #list)
readonly
Listing of records of all jobs; completed and active.
Class Method Summary collapse
Instance Method Summary collapse
-
#active ⇒ Set<JobRecord>
listing of all active jobs.
-
#add(job) ⇒ Object
Track and record the given job.
-
#complete_job(job) ⇒ Object
Complete the given active job.
- #find(id) ⇒ Object
-
#initialize ⇒ JobManager
constructor
A new instance of JobManager.
- #terminate_active ⇒ Object
-
#update(job) ⇒ Object
Update the record for the given Job.
-
#uuid ⇒ String
Generate a new Job ID.
Methods included from Logging
add_argument_header, dev, filename, #log_exception, logger, #logger, reset, set_logger, setup
Constructor Details
#initialize ⇒ JobManager
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
#records ⇒ Set<JobRecord> (readonly) Also known as: list
Returns 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
.instance ⇒ Celluloid::Actor(JobManager)
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
11 12 13 |
# File 'lib/mb/job_manager.rb', line 11 def running? MB::Application[:job_manager] && instance.alive? end |
.stopped? ⇒ Boolean
15 16 17 |
# File 'lib/mb/job_manager.rb', line 15 def stopped? !running? end |
Instance Method Details
#active ⇒ Set<JobRecord>
listing of all active jobs
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
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
50 51 52 |
# File 'lib/mb/job_manager.rb', line 50 def complete_job(job) @_active.delete(job) end |
#find(id) ⇒ Object
63 64 65 |
# File 'lib/mb/job_manager.rb', line 63 def find(id) records.find { |record| record.id == id } end |
#terminate_active ⇒ Object
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
70 71 72 |
# File 'lib/mb/job_manager.rb', line 70 def update(job) find(job.id).update(job) end |
#uuid ⇒ String
Generate a new Job ID
81 82 83 |
# File 'lib/mb/job_manager.rb', line 81 def uuid Celluloid::UUID.generate end |