mirror of
https://github.com/plashchynski/crono.git
synced 2026-03-12 21:35:46 +01:00
Add Schedule
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -7,7 +7,7 @@ module Crono
|
||||
def run
|
||||
load_rails
|
||||
print_banner
|
||||
# start_working_loop
|
||||
start_working_loop
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -5,7 +5,7 @@ module Crono
|
||||
attr_accessor :schedule
|
||||
|
||||
def initialize
|
||||
self.schedule = []
|
||||
self.schedule = Schedule.new
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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
10
lib/crono/schedule.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
module Crono
|
||||
class Schedule
|
||||
def initialize
|
||||
@schedule = []
|
||||
end
|
||||
|
||||
def add(peformer, period)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
15
spec/schedule_spec.rb
Normal 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
|
||||
Reference in New Issue
Block a user