Skip to content

Commit

Permalink
Merge pull request #19105 from yrudman/pass-nil-to-miq_scheduler-to-i…
Browse files Browse the repository at this point in the history
…gnore-schedule

Allow MiqSchedule to accept nil and skip scheduling

(cherry picked from commit 52f7821)

https://bugzilla.redhat.com/show_bug.cgi?id=1763862
  • Loading branch information
gtanzillo authored and simaishi committed Oct 21, 2019
1 parent 1b32f43 commit 0224c07
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 0224c07

Please sign in to comment.