Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

saas safe query for the good job predecessor

ulferts24d5d6683806
diff --git a/app/workers/cron/quarter_hour_schedule_job.rb b/app/workers/cron/quarter_hour_schedule_job.rb
index dc4cc9e66eb..dc9b7b93b13 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 @@ module Cron::QuarterHourScheduleJob
end
end
end
+
+ def good_job
+ @good_job ||= GoodJob::Job.find(job_id)
+ end
end