Class: GovernorBackground::JobManager

Inherits:
Object
  • Object
show all
Defined in:
lib/governor_background/job_manager.rb

Overview

Tracks the progress of jobs, enables reporting of finished jobs, and cleans stale jobs.

Constant Summary collapse

@@finished_statuses =
%w(completed failed killed).freeze
@@jobs =
[]

Class Method Summary collapse

Class Method Details

.add(job) ⇒ Object

Adds a job to the queue.



10
11
12
# File 'lib/governor_background/job_manager.rb', line 10

def add(job)
  @@jobs << job
end

.clean(time = 1.day.ago) ⇒ Object

Purges any jobs that are older than the specified time. This only removes the job wrapper from memory, it does not cancel a job if it is still running.



17
18
19
# File 'lib/governor_background/job_manager.rb', line 17

def clean(time = 1.day.ago)
  @@jobs.reject!{|j| j.created_at < time}
end

.finished_jobsObject

Returns and purges any jobs that have either been completed, failed, or killed.



23
24
25
26
27
# File 'lib/governor_background/job_manager.rb', line 23

def finished_jobs
  finished_jobs = @@jobs.select{|j| @@finished_statuses.include? j.status }
  @@jobs -= finished_jobs
  return finished_jobs
end