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_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
52 53 54 |
# File 'lib/coupler/scheduler.rb', line 52 def is_started? !@loop.nil? end |
#run_jobs ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/coupler/scheduler.rb', line 26 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_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
47 48 49 50 |
# File 'lib/coupler/scheduler.rb', line 47 def shutdown @loop.exit @loop = nil end |
#start ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/coupler/scheduler.rb', line 36 def start if !is_started? @loop = Thread.new do loop do sleep 10 run_jobs end end end end |