mirror of
https://github.com/plashchynski/crono.git
synced 2026-03-12 05:22:07 +01:00
Add #queue and #next for Schedule
This commit is contained in:
@@ -5,6 +5,16 @@ module Crono
|
||||
end
|
||||
|
||||
def add(peformer, period)
|
||||
@schedule << [peformer, period]
|
||||
end
|
||||
|
||||
def next
|
||||
[queue.first[0], queue.first[1].next]
|
||||
end
|
||||
|
||||
private
|
||||
def queue
|
||||
@schedule.sort { |a,b| a[1].next <=> b[1].next }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,11 +5,16 @@ class TestJob
|
||||
end
|
||||
|
||||
describe Crono::Schedule do
|
||||
describe "#add" do
|
||||
it "should add an entry to schedule" do
|
||||
describe "#next" do
|
||||
it "should return next job in schedule" do
|
||||
@schedule = Crono::Schedule.new
|
||||
@period = Crono::Period.new(1.day)
|
||||
@schedule.add(TestJob, @period)
|
||||
[
|
||||
Crono::Period.new(3.day, at: "18:55"),
|
||||
Crono::Period.new(1.day, at: "15:30"),
|
||||
Crono::Period.new(7.day, at: "06:05")
|
||||
].each { |period| @schedule.add(TestJob, period) }
|
||||
|
||||
expect(@schedule.next).to be_eql([TestJob, 1.day.from_now.change(hour: 15, min: 30)])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user