From fb24d9c5c8a6b47a6c132150b207ba2f30516bff Mon Sep 17 00:00:00 2001 From: Jason Frey Date: Fri, 16 Aug 2019 15:04:39 -0400 Subject: [PATCH] Merge pull request #19153 from d-m-u/rufus_upgrade Update rufus-scheduler to 3.6 (cherry picked from commit a8aee202cf24d4bf1c176a33b0bb6e676fdee655) https://bugzilla.redhat.com/show_bug.cgi?id=1743211 --- Gemfile | 6 ++++-- app/models/miq_schedule_worker/runner.rb | 16 ++++++++++------ config/initializers/convert_time_to_eo.rb | 12 ++++++++++++ spec/models/miq_schedule_worker/jobs_spec.rb | 2 +- .../models/miq_schedule_worker/scheduler_spec.rb | 2 +- 5 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 config/initializers/convert_time_to_eo.rb diff --git a/Gemfile b/Gemfile index c26ded97b23..b76ad993f56 100644 --- a/Gemfile +++ b/Gemfile @@ -191,9 +191,11 @@ group :graphql_api, :manageiq_default do end group :scheduler, :manageiq_default do - # Modified gems (forked on Github) - gem "rufus-scheduler", "=3.1.10.2", :git => "https://github.com/ManageIQ/rufus-scheduler.git", :require => false, :tag => "v3.1.10-2" + gem "rufus-scheduler" end +# rufus has et-orbi dependency +# this is temporary inclusion till we can get ConvertTimeToEoTime patch into upstream: +gem "et-orbi" group :seed, :manageiq_default do manageiq_plugin "manageiq-content" diff --git a/app/models/miq_schedule_worker/runner.rb b/app/models/miq_schedule_worker/runner.rb index 66e51e603b2..b63a240dd50 100644 --- a/app/models/miq_schedule_worker/runner.rb +++ b/app/models/miq_schedule_worker/runner.rb @@ -77,15 +77,19 @@ def schedules_for_all_roles # Schedule - Log current system configuration every = worker_settings[:log_active_configuration_interval] - scheduler.schedule_every(every, :tags => [:vmdb_appliance_log_config, schedule_category]) do - enqueue(:vmdb_appliance_log_config) - end + scheduler.schedule_every( + every, + :first_in => every, + :tags => [:vmdb_appliance_log_config, schedule_category] + ) { enqueue(:vmdb_appliance_log_config) } # Schedule - Log current database statistics and bloat every = worker_settings[:log_database_statistics_interval] - scheduler.schedule_every(every, :tags => [:log_all_database_statistics, schedule_category]) do - enqueue(:vmdb_database_log_all_database_statistics) - end + scheduler.schedule_every( + every, + :first_in => every, + :tags => [:log_all_database_statistics, schedule_category] + ) { enqueue(:vmdb_database_log_all_database_statistics) } # Schedule - Update Server Statistics every = worker_settings[:server_stats_interval] diff --git a/config/initializers/convert_time_to_eo.rb b/config/initializers/convert_time_to_eo.rb new file mode 100644 index 00000000000..7d0f9f10471 --- /dev/null +++ b/config/initializers/convert_time_to_eo.rb @@ -0,0 +1,12 @@ +# temporary hack for when/if we can get patch accepted upscream +# et-orbi doesn't support comparisons of EoTime in the scheduler with user provided Time objects +# see https://github.com/ManageIQ/manageiq/pull/19153#issuecomment-521719495 +module ConvertTimeToEoTime + def ==(*args) + o = EtOrbi.make_time(args.first) if args.first.kind_of?(Time) || args.first.kind_of?(DateTime) + super(o) + end +end + +require 'et-orbi' +EtOrbi::EoTime.prepend(ConvertTimeToEoTime) diff --git a/spec/models/miq_schedule_worker/jobs_spec.rb b/spec/models/miq_schedule_worker/jobs_spec.rb index d67afde2d37..2f329869aa2 100644 --- a/spec/models/miq_schedule_worker/jobs_spec.rb +++ b/spec/models/miq_schedule_worker/jobs_spec.rb @@ -29,7 +29,7 @@ schedule_id = 123 scheduler = Rufus::Scheduler.new block = -> { "some work" } - rufus_job = Rufus::Scheduler::EveryJob.new(scheduler, 1.hour, {}, block) + rufus_job = Rufus::Scheduler::EveryJob.new(scheduler, 1.hour.to_i, {}, block) expect(MiqSchedule).to receive(:queue_scheduled_work).with(schedule_id, rufus_job.job_id, 1.hour.from_now.to_i, {}) diff --git a/spec/models/miq_schedule_worker/scheduler_spec.rb b/spec/models/miq_schedule_worker/scheduler_spec.rb index 43b40e408f0..9e408a0291e 100644 --- a/spec/models/miq_schedule_worker/scheduler_spec.rb +++ b/spec/models/miq_schedule_worker/scheduler_spec.rb @@ -72,7 +72,7 @@ scheduler.schedule_cron("0 0 * * *", :tags => [:a, :b], &work) job = rufus_scheduler.jobs.first - expect(job.frequency).to eq(1.day) + expect(job.rough_frequency).to eq(1.day.to_i) expect(job.tags).to match_array(%w(a b)) expect(job.callable).to eq(work) end