From 59e71e89f3ebc8d4771dd4cb28a8e9a5f1903737 Mon Sep 17 00:00:00 2001 From: Dzmitry Plashchynski Date: Thu, 5 Mar 2015 15:13:48 +0200 Subject: [PATCH] Rename Schedule to Scheduler --- examples/monitrc.conf | 2 +- lib/crono.rb | 2 +- lib/crono/cli.rb | 10 +++++----- lib/crono/performer_proxy.rb | 8 ++++---- lib/crono/{schedule.rb => scheduler.rb} | 2 +- spec/performer_proxy_spec.rb | 2 +- spec/{schedule_spec.rb => scheduler_spec.rb} | 10 +++++----- 7 files changed, 18 insertions(+), 18 deletions(-) rename lib/crono/{schedule.rb => scheduler.rb} (93%) rename spec/{schedule_spec.rb => scheduler_spec.rb} (71%) diff --git a/examples/monitrc.conf b/examples/monitrc.conf index 23d30b2..fe8cd6e 100644 --- a/examples/monitrc.conf +++ b/examples/monitrc.conf @@ -1,6 +1,6 @@ check process crono_myapp with pidfile /path/to/crono.pid - start program = "bundle exec crono" with timeout 30 seconds + start program = "bundle exec crono -e production" with timeout 30 seconds stop program = "kill -s TERM `cat /path/to/crono.pid`" with timeout 30 seconds if totalmem is greater than 500 MB for 2 cycles then restart group myapp_crono diff --git a/lib/crono.rb b/lib/crono.rb index f23e1fa..2c4565b 100644 --- a/lib/crono.rb +++ b/lib/crono.rb @@ -5,6 +5,6 @@ require "active_support/all" require "crono/version.rb" require "crono/period.rb" require "crono/job.rb" -require "crono/schedule.rb" +require "crono/scheduler.rb" require "crono/config.rb" require "crono/performer_proxy.rb" diff --git a/lib/crono/cli.rb b/lib/crono/cli.rb index 11454e3..50580c4 100644 --- a/lib/crono/cli.rb +++ b/lib/crono/cli.rb @@ -2,7 +2,7 @@ require 'crono' require 'optparse' module Crono - mattr_accessor :schedule + mattr_accessor :scheduler mattr_accessor :logger class CLI @@ -12,7 +12,7 @@ module Crono def initialize self.config = Config.new - Crono.schedule = Schedule.new + Crono.scheduler = Scheduler.new end def run @@ -49,8 +49,8 @@ module Crono def print_banner logger.info "Loading Crono #{Crono::VERSION}" logger.info "Running in #{RUBY_DESCRIPTION}" - logger.info "Schedule:" - Crono.schedule.jobs.each do |job| + logger.info "Jobs:" + Crono.scheduler.jobs.each do |job| logger.info job.description end end @@ -65,7 +65,7 @@ module Crono def start_working_loop Thread.abort_on_exception = true - while job = Crono.schedule.next do + while job = Crono.scheduler.next do sleep(job.next - Time.now) job.perform end diff --git a/lib/crono/performer_proxy.rb b/lib/crono/performer_proxy.rb index 4bab9ac..707544d 100644 --- a/lib/crono/performer_proxy.rb +++ b/lib/crono/performer_proxy.rb @@ -1,17 +1,17 @@ module Crono class PerformerProxy - def initialize(performer, schedule) + def initialize(performer, scheduler) @performer = performer - @schedule = schedule + @scheduler = scheduler end def every(period, *args) job = Job.new(@performer, Period.new(period, *args)) - @schedule.add(job) + @scheduler.add(job) end end def self.perform(performer) - PerformerProxy.new(performer, Crono.schedule) + PerformerProxy.new(performer, Crono.scheduler) end end diff --git a/lib/crono/schedule.rb b/lib/crono/scheduler.rb similarity index 93% rename from lib/crono/schedule.rb rename to lib/crono/scheduler.rb index 8fc564e..3b297f1 100644 --- a/lib/crono/schedule.rb +++ b/lib/crono/scheduler.rb @@ -1,5 +1,5 @@ module Crono - class Schedule + class Scheduler attr_accessor :jobs def initialize diff --git a/spec/performer_proxy_spec.rb b/spec/performer_proxy_spec.rb index a43bc16..5d9630c 100644 --- a/spec/performer_proxy_spec.rb +++ b/spec/performer_proxy_spec.rb @@ -6,7 +6,7 @@ end describe Crono::PerformerProxy do it "should add job to schedule" do - expect(Crono.schedule).to receive(:add).with(kind_of(Crono::Job)) + expect(Crono.scheduler).to receive(:add).with(kind_of(Crono::Job)) Crono.perform(TestJob).every(2.days, at: "15:30") end end diff --git a/spec/schedule_spec.rb b/spec/scheduler_spec.rb similarity index 71% rename from spec/schedule_spec.rb rename to spec/scheduler_spec.rb index 1b9c3cb..d2e23b3 100644 --- a/spec/schedule_spec.rb +++ b/spec/scheduler_spec.rb @@ -4,24 +4,24 @@ class TestJob def perform;end end -describe Crono::Schedule do +describe Crono::Scheduler do before(:each) do - @schedule = Crono::Schedule.new + @scheduler = Crono::Scheduler.new @jobs = [ Crono::Period.new(3.day, at: "18:55"), Crono::Period.new(1.day, at: "15:30"), Crono::Period.new(7.day, at: "06:05") ].map { |period| Crono::Job.new(TestJob, period) } - @schedule.jobs = @jobs + @scheduler.jobs = @jobs end describe "#next" do it "should return next job in schedule" do - expect(@schedule.next).to be @jobs[1] + expect(@scheduler.next).to be @jobs[1] end it "should return next based on last" do - expect(@schedule.next) + expect(@scheduler.next) end end end