Skip to content

Commit

Permalink
passing first argument nil or empty string to MiqShedule will skip sc…
Browse files Browse the repository at this point in the history
…heduling instead of raising error

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1736749
  • Loading branch information
yrudman committed Aug 6, 2019
1 parent 45da279 commit f02afae
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?
if duration.blank?
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 f02afae

Please sign in to comment.