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

GoodJob concurrency for HealthStatusMailerJob

Andreas Pfohl38bba33faa5b
diff --git a/modules/storages/app/services/storages/health_service.rb b/modules/storages/app/services/storages/health_service.rb
index f7a704a53a9..ac2ecc02dbf 100644
--- a/modules/storages/app/services/storages/health_service.rb
+++ b/modules/storages/app/services/storages/health_service.rb
@@ -71,7 +71,7 @@ module Storages
notify_unhealthy_admin_users
end
- schedule_mail_job(@storage) unless mail_job_exists?
+ schedule_mail_job(@storage)
end
private
@@ -91,10 +91,6 @@ module Storages
::Storages::HealthStatusMailerJob.schedule(storage:)
end
- def mail_job_exists?
- Delayed::Job.where("handler LIKE ?", "%job_class: Storages::HealthStatusMailerJob%").any?
- end
-
def reason_is_same(new_health_reason)
@storage.health_reason_identifier == ::Storages::Storage.extract_part_from_piped_string(new_health_reason, 0)
end
diff --git a/modules/storages/app/workers/storages/health_status_mailer_job.rb b/modules/storages/app/workers/storages/health_status_mailer_job.rb
index ae715f5b2ed..a00c064f815 100644
--- a/modules/storages/app/workers/storages/health_status_mailer_job.rb
+++ b/modules/storages/app/workers/storages/health_status_mailer_job.rb
@@ -30,6 +30,15 @@
module Storages
class HealthStatusMailerJob < ApplicationJob
+ include GoodJob::ActiveJobExtensions::Concurrency
+
+ good_job_control_concurrency_with(
+ total_limit: 1,
+ enqueue_limit: 1,
+ perform_limit: 1,
+ key: self.class.name
+ )
+
def perform(storage:)
return unless Storages::Storage.exists?(storage.id)
@@ -56,7 +65,7 @@ module Storages
def admin_users
User.where(admin: true)
- .where.not(mail: [nil, ''])
+ .where.not(mail: [nil, ""])
end
end
end