Rename Schedule to Scheduler

This commit is contained in:
Dzmitry Plashchynski
2015-03-05 15:13:48 +02:00
parent 368d9ee0a9
commit 59e71e89f3
7 changed files with 18 additions and 18 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
check process crono_myapp check process crono_myapp
with pidfile /path/to/crono.pid 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 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 if totalmem is greater than 500 MB for 2 cycles then restart
group myapp_crono group myapp_crono
+1 -1
View File
@@ -5,6 +5,6 @@ require "active_support/all"
require "crono/version.rb" require "crono/version.rb"
require "crono/period.rb" require "crono/period.rb"
require "crono/job.rb" require "crono/job.rb"
require "crono/schedule.rb" require "crono/scheduler.rb"
require "crono/config.rb" require "crono/config.rb"
require "crono/performer_proxy.rb" require "crono/performer_proxy.rb"
+5 -5
View File
@@ -2,7 +2,7 @@ require 'crono'
require 'optparse' require 'optparse'
module Crono module Crono
mattr_accessor :schedule mattr_accessor :scheduler
mattr_accessor :logger mattr_accessor :logger
class CLI class CLI
@@ -12,7 +12,7 @@ module Crono
def initialize def initialize
self.config = Config.new self.config = Config.new
Crono.schedule = Schedule.new Crono.scheduler = Scheduler.new
end end
def run def run
@@ -49,8 +49,8 @@ module Crono
def print_banner def print_banner
logger.info "Loading Crono #{Crono::VERSION}" logger.info "Loading Crono #{Crono::VERSION}"
logger.info "Running in #{RUBY_DESCRIPTION}" logger.info "Running in #{RUBY_DESCRIPTION}"
logger.info "Schedule:" logger.info "Jobs:"
Crono.schedule.jobs.each do |job| Crono.scheduler.jobs.each do |job|
logger.info job.description logger.info job.description
end end
end end
@@ -65,7 +65,7 @@ module Crono
def start_working_loop def start_working_loop
Thread.abort_on_exception = true Thread.abort_on_exception = true
while job = Crono.schedule.next do while job = Crono.scheduler.next do
sleep(job.next - Time.now) sleep(job.next - Time.now)
job.perform job.perform
end end
+4 -4
View File
@@ -1,17 +1,17 @@
module Crono module Crono
class PerformerProxy class PerformerProxy
def initialize(performer, schedule) def initialize(performer, scheduler)
@performer = performer @performer = performer
@schedule = schedule @scheduler = scheduler
end end
def every(period, *args) def every(period, *args)
job = Job.new(@performer, Period.new(period, *args)) job = Job.new(@performer, Period.new(period, *args))
@schedule.add(job) @scheduler.add(job)
end end
end end
def self.perform(performer) def self.perform(performer)
PerformerProxy.new(performer, Crono.schedule) PerformerProxy.new(performer, Crono.scheduler)
end end
end end
@@ -1,5 +1,5 @@
module Crono module Crono
class Schedule class Scheduler
attr_accessor :jobs attr_accessor :jobs
def initialize def initialize
+1 -1
View File
@@ -6,7 +6,7 @@ end
describe Crono::PerformerProxy do describe Crono::PerformerProxy do
it "should add job to schedule" 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") Crono.perform(TestJob).every(2.days, at: "15:30")
end end
end end
@@ -4,24 +4,24 @@ class TestJob
def perform;end def perform;end
end end
describe Crono::Schedule do describe Crono::Scheduler do
before(:each) do before(:each) do
@schedule = Crono::Schedule.new @scheduler = Crono::Scheduler.new
@jobs = [ @jobs = [
Crono::Period.new(3.day, at: "18:55"), Crono::Period.new(3.day, at: "18:55"),
Crono::Period.new(1.day, at: "15:30"), Crono::Period.new(1.day, at: "15:30"),
Crono::Period.new(7.day, at: "06:05") Crono::Period.new(7.day, at: "06:05")
].map { |period| Crono::Job.new(TestJob, period) } ].map { |period| Crono::Job.new(TestJob, period) }
@schedule.jobs = @jobs @scheduler.jobs = @jobs
end end
describe "#next" do describe "#next" do
it "should return next job in schedule" do it "should return next job in schedule" do
expect(@schedule.next).to be @jobs[1] expect(@scheduler.next).to be @jobs[1]
end end
it "should return next based on last" do it "should return next based on last" do
expect(@schedule.next) expect(@scheduler.next)
end end
end end
end end