Skip to content

Commit

Permalink
Merge pull request #15637 from opf/fix/saas_safe_good_job_predecessor…
Browse files Browse the repository at this point in the history
…_finding

Fix/saas safe good job predecessor finding
  • Loading branch information
ulferts authored May 22, 2024
2 parents 7d07aac + 24d5d66 commit f2be52d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion app/models/users/scopes/having_reminder_mail_to_send.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 11 additions & 4 deletions app/workers/cron/quarter_hour_schedule_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -72,4 +75,8 @@ def lower_boundary
end
end
end

def good_job
@good_job ||= GoodJob::Job.find(job_id)
end
end

0 comments on commit f2be52d

Please sign in to comment.