Class: Coupler::Scheduler
- Inherits:
-
Object
- Object
- Coupler::Scheduler
- Includes:
- Singleton
- Defined in:
- lib/coupler/scheduler.rb
Instance Method Summary collapse
-
#initialize ⇒ Scheduler
constructor
A new instance of Scheduler.
- #is_started? ⇒ Boolean
- #run_jobs ⇒ Object
- #schedule_import_job(import) ⇒ Object
- #schedule_run_scenario_job(scenario) ⇒ Object
- #schedule_transform_job(resource) ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize ⇒ Scheduler
Returns a new instance of Scheduler.
5 6 7 8 |
# File 'lib/coupler/scheduler.rb', line 5 def initialize super @mutex = Mutex.new end |
Instance Method Details
#is_started? ⇒ Boolean
60 61 62 |
# File 'lib/coupler/scheduler.rb', line 60 def is_started? !@loop.nil? end |
#run_jobs ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/coupler/scheduler.rb', line 34 def run_jobs @mutex.synchronize do count = Models::Job.filter(:status => 'running').count if count == 0 job = Models::Job.filter(:status => 'scheduled').order(:created_at).first Thread.new(job) { |j| j.execute } if job end end end |
#schedule_import_job(import) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/coupler/scheduler.rb', line 26 def schedule_import_job(import) Models::Job.create({ :name => "import", :import => import, :status => "scheduled" }) end |
#schedule_run_scenario_job(scenario) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/coupler/scheduler.rb', line 18 def schedule_run_scenario_job(scenario) Models::Job.create({ :name => "run_scenario", :scenario => scenario, :status => "scheduled" }) end |
#schedule_transform_job(resource) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/coupler/scheduler.rb', line 10 def schedule_transform_job(resource) Models::Job.create({ :name => "transform", :resource => resource, :status => "scheduled" }) end |
#shutdown ⇒ Object
55 56 57 58 |
# File 'lib/coupler/scheduler.rb', line 55 def shutdown @loop.exit @loop = nil end |
#start ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/coupler/scheduler.rb', line 44 def start if !is_started? @loop = Thread.new do loop do sleep 10 run_jobs end end end end |