Skip to content

Commit

Permalink
Let #schedule accept a CronLine instance
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed May 16, 2017
1 parent c7cfd23 commit 63511c8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
2 changes: 2 additions & 0 deletions lib/rufus/scheduler/jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,8 @@ def next_time_from(time)

class CronJob < RepeatJob

attr_reader :cron_line

def initialize(scheduler, cronline, opts, block)

super(scheduler, cronline, opts, block)
Expand Down
2 changes: 1 addition & 1 deletion lib/rufus/scheduler/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def self.parse(o, opts={})

def self.parse_cron(o, opts)

CronLine.new(o)
o.is_a?(CronLine) ? o : CronLine.new(o)

rescue ArgumentError => ae

Expand Down
11 changes: 0 additions & 11 deletions spec/job_cron_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@

expect(job.last_time.to_i % 10).to eq(0)
end

context 'when passed a cronline object' do
it 'triggers near the zero second' do
cl = Rufus::Scheduler::CronLine.new('* * * * *')
job = @scheduler.schedule_cron cl do; end

sleep_until_next_minute

expect(job.last_time.to_i % 10).to eq(0)
end
end
end

#context 'sub-minute' do
Expand Down
17 changes: 17 additions & 0 deletions spec/schedule_cron_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@
@scheduler.cron '* * * * * *' do; end
}.to raise_error(ArgumentError)
end

it 'accepts a CronLine instance' do

cl = Rufus::Scheduler::CronLine.new('* * * * *')
job_id = @scheduler.cron(cl) {}
job = @scheduler.job(job_id)

expect(job.cron_line.object_id).to eq(cl.object_id)
end
end

describe '#schedule_cron' do
Expand All @@ -61,6 +70,14 @@
expect(job.original).to eq('* * * * *')
expect(job.job_id).to match(/^cron_/)
end

it 'accepts a CronLine instance' do

cl = Rufus::Scheduler::CronLine.new('* * * * *')
job = @scheduler.schedule_cron(cl) {}

expect(job.cron_line.object_id).to eq(cl.object_id)
end
end
end

8 changes: 8 additions & 0 deletions spec/schedule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@

expect(opts.size).to eq(1)
end

it 'accepts a CronLine instance' do

cl = Rufus::Scheduler::CronLine.new('* * * * *')
job = @scheduler.schedule(cl) {}

expect(job.cron_line.object_id).to eq(cl.object_id)
end
end

describe '#at' do
Expand Down

0 comments on commit 63511c8

Please sign in to comment.