mirror of
https://github.com/plashchynski/crono.git
synced 2026-04-21 00:11:34 +02:00
Merge branch 'master' into materialize_css
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
PATH
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
crono (0.8.5.pre)
|
crono (0.8.7.pre)
|
||||||
activejob (~> 4.0)
|
activejob (~> 4.0)
|
||||||
activerecord (~> 4.0)
|
activerecord (~> 4.0)
|
||||||
activesupport (~> 4.0)
|
activesupport (~> 4.0)
|
||||||
@@ -31,7 +31,7 @@ GEM
|
|||||||
columnize (= 0.9.0)
|
columnize (= 0.9.0)
|
||||||
columnize (0.9.0)
|
columnize (0.9.0)
|
||||||
diff-lcs (1.2.5)
|
diff-lcs (1.2.5)
|
||||||
globalid (0.3.3)
|
globalid (0.3.5)
|
||||||
activesupport (>= 4.1.0)
|
activesupport (>= 4.1.0)
|
||||||
haml (4.0.6)
|
haml (4.0.6)
|
||||||
tilt
|
tilt
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ module Crono
|
|||||||
logger.info 'Jobs:'
|
logger.info 'Jobs:'
|
||||||
Crono.scheduler.jobs.each do |job|
|
Crono.scheduler.jobs.each do |job|
|
||||||
logger.info "'#{job.performer}' with rule '#{job.period.description}'"\
|
logger.info "'#{job.performer}' with rule '#{job.period.description}'"\
|
||||||
"next time will perform at #{job.next}"
|
" next time will perform at #{job.next}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -80,9 +80,9 @@ module Crono
|
|||||||
end
|
end
|
||||||
|
|
||||||
def start_working_loop
|
def start_working_loop
|
||||||
while true
|
loop do
|
||||||
next_time, jobs = Crono.scheduler.next_jobs
|
next_time, jobs = Crono.scheduler.next_jobs
|
||||||
sleep(next_time - Time.now)
|
sleep(next_time - Time.now) if next_time > Time.now
|
||||||
jobs.each(&:perform)
|
jobs.each(&:perform)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -60,9 +60,7 @@ module Crono
|
|||||||
end
|
end
|
||||||
|
|
||||||
def perform_job
|
def perform_job
|
||||||
performer_instance = performer.new
|
performer.new.perform
|
||||||
performer_instance.instance_variable_set(:@_crono_job, self)
|
|
||||||
performer_instance.perform
|
|
||||||
finished_time_sec = format('%.2f', Time.now - last_performed_at)
|
finished_time_sec = format('%.2f', Time.now - last_performed_at)
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
handle_job_fail(e, finished_time_sec)
|
handle_job_fail(e, finished_time_sec)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
module Crono
|
module Crono
|
||||||
# Period describe frequency of performing a task
|
# Period describe frequency of jobs
|
||||||
class Period
|
class Period
|
||||||
DAYS = [:monday, :tuesday, :wednesday, :thursday, :friday, :saturday,
|
DAYS = [:monday, :tuesday, :wednesday, :thursday, :friday, :saturday,
|
||||||
:sunday]
|
:sunday]
|
||||||
@@ -14,7 +14,9 @@ module Crono
|
|||||||
return initial_next unless since
|
return initial_next unless since
|
||||||
@next = @period.since(since)
|
@next = @period.since(since)
|
||||||
@next = @next.beginning_of_week.advance(days: @on) if @on
|
@next = @next.beginning_of_week.advance(days: @on) if @on
|
||||||
@next.change(time_atts)
|
@next = @next.change(time_atts)
|
||||||
|
return @next if @next.future?
|
||||||
|
Time.now
|
||||||
end
|
end
|
||||||
|
|
||||||
def description
|
def description
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
module Crono
|
module Crono
|
||||||
VERSION = '0.8.5.pre'
|
VERSION = '0.8.7.pre'
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -32,23 +32,10 @@ describe Crono::Job do
|
|||||||
expect(saved_log).to include 'Some error'
|
expect(saved_log).to include 'Some error'
|
||||||
end
|
end
|
||||||
|
|
||||||
xit 'should set Job#healthy to true if perform ok' do
|
|
||||||
class TestJob
|
|
||||||
def perform
|
|
||||||
@_crono_job
|
|
||||||
end
|
|
||||||
end
|
|
||||||
job.perform.join
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should set Job#healthy to false if perform with error' do
|
it 'should set Job#healthy to false if perform with error' do
|
||||||
failing_job.perform.join
|
failing_job.perform.join
|
||||||
expect(failing_job.healthy).to be false
|
expect(failing_job.healthy).to be false
|
||||||
end
|
end
|
||||||
|
|
||||||
xit 'should set @_crono_job variable to instance' do
|
|
||||||
job.perform
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#description' do
|
describe '#description' do
|
||||||
|
|||||||
@@ -53,28 +53,33 @@ describe Crono::Period do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'in daily basis' do
|
context 'in daily basis' do
|
||||||
|
it "should return Time.now if the next time in past" do
|
||||||
|
@period = Crono::Period.new(1.day, at: '06:00')
|
||||||
|
expect(@period.next(since: 2.days.ago)).to be_eql(Time.now)
|
||||||
|
end
|
||||||
|
|
||||||
it 'should return the time 2 days from now' do
|
it 'should return the time 2 days from now' do
|
||||||
@period = Crono::Period.new(2.day)
|
@period = Crono::Period.new(2.day)
|
||||||
expect(@period.next).to be_eql(2.day.from_now)
|
expect(@period.next).to be_eql(2.days.from_now)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should set time to 'at' time as a string" do
|
it "should set time to 'at' time as a string" do
|
||||||
time = 10.minutes.ago
|
time = 10.minutes.ago
|
||||||
at = [time.hour, time.min].join(':')
|
at = [time.hour, time.min].join(':')
|
||||||
@period = Crono::Period.new(2.day, at: at)
|
@period = Crono::Period.new(2.days, at: at)
|
||||||
expect(@period.next).to be_eql(2.day.from_now.change(hour: time.hour, min: time.min))
|
expect(@period.next).to be_eql(2.days.from_now.change(hour: time.hour, min: time.min))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should set time to 'at' time as a hash" do
|
it "should set time to 'at' time as a hash" do
|
||||||
time = 10.minutes.ago
|
time = 10.minutes.ago
|
||||||
at = { hour: time.hour, min: time.min }
|
at = { hour: time.hour, min: time.min }
|
||||||
@period = Crono::Period.new(2.day, at: at)
|
@period = Crono::Period.new(2.days, at: at)
|
||||||
expect(@period.next).to be_eql(2.day.from_now.change(at))
|
expect(@period.next).to be_eql(2.days.from_now.change(at))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should raise error when 'at' is wrong" do
|
it "should raise error when 'at' is wrong" do
|
||||||
expect {
|
expect {
|
||||||
Crono::Period.new(2.day, at: 1)
|
Crono::Period.new(2.days, at: 1)
|
||||||
}.to raise_error("Unknown 'at' format")
|
}.to raise_error("Unknown 'at' format")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -85,14 +90,14 @@ describe Crono::Period do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'should return time in relation to last time' do
|
it 'should return time in relation to last time' do
|
||||||
@period = Crono::Period.new(2.day)
|
@period = Crono::Period.new(2.days)
|
||||||
expect(@period.next(since: 1.day.ago)).to be_eql(1.day.from_now)
|
expect(@period.next(since: 1.day.ago)).to be_eql(1.day.from_now)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return today time if it is first run and not too late' do
|
it 'should return today time if it is first run and not too late' do
|
||||||
time = 10.minutes.from_now
|
time = 10.minutes.from_now
|
||||||
at = { hour: time.hour, min: time.min }
|
at = { hour: time.hour, min: time.min }
|
||||||
@period = Crono::Period.new(2.day, at: at)
|
@period = Crono::Period.new(2.days, at: at)
|
||||||
expect(@period.next.utc.to_s).to be_eql(Time.now.change(at).utc.to_s)
|
expect(@period.next.utc.to_s).to be_eql(Time.now.change(at).utc.to_s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user