diff --git a/app/models/users/scopes/having_reminder_mail_to_send.rb b/app/models/users/scopes/having_reminder_mail_to_send.rb index 24d03c4ca0b1..0b59bce243f4 100644 --- a/app/models/users/scopes/having_reminder_mail_to_send.rb +++ b/app/models/users/scopes/having_reminder_mail_to_send.rb @@ -175,7 +175,8 @@ def build_local_times(times, zone) end def quarters_between_earliest_and_latest(earliest_time, latest_time) # rubocop:disable Metrics/AbcSize - raise ArgumentError if latest_time < earliest_time || (latest_time - earliest_time) > 1.day + raise ArgumentError, "#{latest_time} < #{earliest_time}" if latest_time < earliest_time + raise ArgumentError, "#{latest_time} - #{earliest_time} > 1 day" if (latest_time - earliest_time) > 1.day # The first quarter is equal or greater to the earliest time first_quarter = earliest_time.change(min: (earliest_time.min.to_f / 15).ceil * 15) diff --git a/app/workers/cron/quarter_hour_schedule_job.rb b/app/workers/cron/quarter_hour_schedule_job.rb index dc4cc9e66eb9..dc9b7b93b13f 100644 --- a/app/workers/cron/quarter_hour_schedule_job.rb +++ b/app/workers/cron/quarter_hour_schedule_job.rb @@ -52,16 +52,19 @@ module Cron::QuarterHourScheduleJob private def upper_boundary - @upper_boundary ||= GoodJob::Job - .find(job_id) - .cron_at + @upper_boundary ||= good_job.cron_at end def lower_boundary @lower_boundary ||= begin + # The cron_key is used here to find the predecessor job. + # The job_class has been used before as a comparison but this fails in + # the SaaS environment where multiple tenants exist. The cron_key gets the + # tenant information prepended and is thus scoped to the tenant. predecessor = GoodJob::Job .succeeded - .where(job_class: self.class.name) + .where(cron_key: good_job.cron_key) + .where("cron_at < ?", upper_boundary) .order(cron_at: :desc) .first @@ -72,4 +75,8 @@ def lower_boundary end end end + + def good_job + @good_job ||= GoodJob::Job.find(job_id) + end end