Skip to content

Commit

Permalink
passing first argument nil to MiqShedule will skip scheduling instead…
Browse files Browse the repository at this point in the history
  • Loading branch information
yrudman committed Aug 6, 2019
1 parent 45da279 commit 246c6f3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion app/models/miq_schedule_worker/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ def initialize(logger, role_schedule, rufus_scheduler)
end

def schedule_every(duration = nil, callable = nil, opts = {}, &block)
raise ArgumentError if duration.nil?
unless duration.present?
logger.warn("Duration is empty, scheduling ingnored. Called from: #{block}.")
return
end

role_schedule << rufus_scheduler.schedule_every(duration, callable, opts, &block)
rescue ArgumentError => err
logger.error("#{err.class} for schedule_every with [#{duration}, #{opts.inspect}]. Called from: #{caller[1]}.")
Expand Down
4 changes: 2 additions & 2 deletions spec/models/miq_schedule_worker/scheduler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
end

context "with different parmeters" do
it "catches an error on nil first arg" do
expect(logger).to receive(:error).once.with(/scheduler_spec.rb/)
it "interprets first arg nil as trigger to skip scheduling" do
expect(logger).to receive(:warn).once.with(/Duration is empty, scheduling ingnored/)
scheduler.schedule_every(nil) {}
end

Expand Down

0 comments on commit 246c6f3

Please sign in to comment.