Add Schedule

This commit is contained in:
Dzmitry Plashchynski
2015-03-03 15:11:19 +02:00
parent 2c78115ce7
commit 518160d5d9
9 changed files with 38 additions and 7 deletions

View File

@@ -4,5 +4,6 @@ end
require "active_support/all"
require "crono/version.rb"
require "crono/period.rb"
require "crono/schedule.rb"
require "crono/config.rb"
require "crono/performer_proxy.rb"

View File

@@ -7,7 +7,7 @@ module Crono
def run
load_rails
print_banner
# start_working_loop
start_working_loop
end
private

View File

@@ -5,7 +5,7 @@ module Crono
attr_accessor :schedule
def initialize
self.schedule = []
self.schedule = Schedule.new
end
end
end

View File

@@ -5,7 +5,7 @@ module Crono
end
def every(period, *args)
Config.instance.schedule += [@performer, Period.new(period, *args)]
Config.instance.schedule.add(@performer, Period.new(period, *args))
end
end

10
lib/crono/schedule.rb Normal file
View File

@@ -0,0 +1,10 @@
module Crono
class Schedule
def initialize
@schedule = []
end
def add(peformer, period)
end
end
end

View File

@@ -9,8 +9,9 @@ describe Crono::CLI do
let(:cli) { Crono::CLI.instance }
describe "#run" do
it "should try to initialize rails with #load_rails" do
it "should try to initialize rails with #load_rails and start working loop" do
expect(cli).to receive(:load_rails)
expect(cli).to receive(:start_working_loop)
cli.run
end
end
@@ -21,4 +22,8 @@ describe Crono::CLI do
expect(thread).to be_stop
end
end
describe "#start_working_loop" do
it "should start working loop"
end
end

View File

@@ -2,9 +2,9 @@ require "spec_helper"
describe Crono::Config do
describe "#initialize" do
it "should initialize schedule with an empty array" do
it "should initialize schedule" do
@config = Crono::Config.instance
expect(@config.schedule).to eql([])
expect(@config.schedule).to be_a(Crono::Schedule)
end
end
end

View File

@@ -6,7 +6,7 @@ end
describe Crono::PerformerProxy do
it "should add job and period to schedule" do
expect(Crono::Config.instance.schedule).to receive(:add).with(TestJob, kind_of(Crono::Period))
Crono.perform(TestJob).every(2.days, at: "15:30")
expect(Crono::Config.instance.schedule).to_not be_empty
end
end

15
spec/schedule_spec.rb Normal file
View File

@@ -0,0 +1,15 @@
require "spec_helper"
class TestJob
def perform;end
end
describe Crono::Schedule do
describe "#add" do
it "should add an entry to schedule" do
@schedule = Crono::Schedule.new
@period = Crono::Period.new(1.day)
@schedule.add(TestJob, @period)
end
end
end