Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow MiqSchedule to accept nil and skip scheduling #19105

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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