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

Introduce cron job to ensure Init jobs get scheduled after error

Oliver Günther0eae2d63b1d5
diff --git a/config/initializers/cronjobs.rb b/config/initializers/cronjobs.rb
index 36962202154..ffe5b4c14ef 100644
--- a/config/initializers/cronjobs.rb
+++ b/config/initializers/cronjobs.rb
@@ -65,6 +65,10 @@ Rails.application.config.after_initialize do
"Ldap::SynchronizationJob": {
cron: "30 23 * * *",
class: Ldap::SynchronizationJob.name
+ },
+ "RecurringMeetings::InitNextOccurrenceWatchdogJob": {
+ cron: "11 05 * * *",
+ class: RecurringMeetings::InitNextOccurrenceWatchdogJob.name
}
}
)
diff --git a/modules/meeting/app/workers/recurring_meetings/init_next_occurrence_job.rb b/modules/meeting/app/workers/recurring_meetings/init_next_occurrence_job.rb
index 4ed068ccd69..5e0d56b1d47 100644
--- a/modules/meeting/app/workers/recurring_meetings/init_next_occurrence_job.rb
+++ b/modules/meeting/app/workers/recurring_meetings/init_next_occurrence_job.rb
@@ -31,6 +31,8 @@ module RecurringMeetings
include GoodJob::ActiveJobExtensions::Concurrency
discard_on ActiveJob::DeserializationError
+ CONCURRENCY_KEY_BASE = "RecurringMeetings::InitNextOccurrenceJob-".freeze
+
good_job_control_concurrency_with(
# Allow the running job to enqueue the next one
total_limit: 2,
@@ -47,7 +49,7 @@ module RecurringMeetings
end
def self.unique_key(recurring_meeting)
- "RecurringMeetings::InitNextOccurrenceJob-#{recurring_meeting.id}"
+ "#{CONCURRENCY_KEY_BASE}#{recurring_meeting.id}"
end
attr_accessor :recurring_meeting, :scheduled_time
@@ -74,12 +76,12 @@ module RecurringMeetings
end
if occurrence_cancelled?
- Rails.logger.debug { "Will not create next occurrence for series ##{recurring_meeting.id} is already cancelled" }
+ Rails.logger.debug { "Will not create next occurrence for series ##{recurring_meeting.id} as already cancelled" }
return
end
unless occurring_at_scheduled_time?
- Rails.logger.debug { "The given schedule #{scheduled_time} is (no longer) existing for series ##{recurring_meeting.id}" }
+ Rails.logger.debug { "The given schedule #{scheduled_time} (no longer) exists for series ##{recurring_meeting.id}" }
return
end
diff --git a/modules/meeting/app/workers/recurring_meetings/init_next_occurrence_watchdog_job.rb b/modules/meeting/app/workers/recurring_meetings/init_next_occurrence_watchdog_job.rb
new file mode 100644
index 00000000000..0b99448763d
--- /dev/null
+++ b/modules/meeting/app/workers/recurring_meetings/init_next_occurrence_watchdog_job.rb
@@ -0,0 +1,49 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+class RecurringMeetings::InitNextOccurrenceWatchdogJob < ApplicationJob
+ queue_with_priority :low
+
+ def perform
+ key = RecurringMeetings::InitNextOccurrenceJob::CONCURRENCY_KEY_BASE
+
+ RecurringMeeting
+ .joins("LEFT JOIN good_jobs ON good_jobs.concurrency_key = CONCAT('#{key}', recurring_meetings.id)")
+ .where(good_jobs: { id: nil })
+ .find_each do |series|
+ next_occurrence = series.next_occurrence
+
+ if next_occurrence
+ Rails.logger.warn { "Meeting series ##{series.id} lost its InitNextOccurrenceJob. Re-scheduling." }
+ RecurringMeetings::InitNextOccurrenceJob.perform_later(series, next_occurrence)
+ else
+ Rails.logger.debug { "Meeting series ##{series.id} has no next occurrence. Skipping resetting init job" }
+ end
+ end
+ end
+end