Skip to content

Commit

Permalink
[#48717] Replace DelayedJob with GoodJob.
Browse files Browse the repository at this point in the history
  • Loading branch information
ba1ash committed Aug 30, 2023
1 parent eff2a06 commit ba43300
Show file tree
Hide file tree
Showing 41 changed files with 274 additions and 587 deletions.
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ gem 'multi_json', '~> 1.15.0'
gem 'oj', '~> 3.16.0'

gem 'daemons'
gem 'delayed_cron_job', '~> 0.9.0'
gem 'delayed_job_active_record', '~> 4.1.5'
gem 'good_job'

gem 'rack-protection', '~> 3.1.0'

Expand Down
20 changes: 10 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,6 @@ GEM
deckar01-task_list (2.3.2)
html-pipeline
declarative (0.0.20)
delayed_cron_job (0.9.0)
fugit (>= 1.5)
delayed_job (4.1.11)
activesupport (>= 3.0, < 8.0)
delayed_job_active_record (4.1.7)
activerecord (>= 3.0, < 8.0)
delayed_job (>= 3.0, < 5)
diff-lcs (1.5.0)
disposable (0.6.3)
declarative (>= 0.0.9, < 1.0.0)
Expand Down Expand Up @@ -493,6 +486,14 @@ GEM
i18n (>= 0.7)
multi_json
request_store (>= 1.0)
good_job (3.15.13)
activejob (>= 6.0.0)
activerecord (>= 6.0.0)
concurrent-ruby (>= 1.0.2)
fugit (>= 1.1)
railties (>= 6.0.0)
thor (>= 0.14.1)
webrick (>= 1.3)
google-apis-core (0.11.1)
addressable (~> 2.5, >= 2.5.1)
googleauth (>= 0.16.2, < 2.a)
Expand Down Expand Up @@ -1026,8 +1027,6 @@ DEPENDENCIES
date_validator (~> 0.12.0)
debug
deckar01-task_list (~> 2.3.1)
delayed_cron_job (~> 0.9.0)
delayed_job_active_record (~> 4.1.5)
disposable (~> 0.6.2)
doorkeeper (~> 5.6.6)
dotenv-rails
Expand All @@ -1043,6 +1042,7 @@ DEPENDENCIES
friendly_id (~> 5.5.0)
fuubar (~> 2.5.0)
gon (~> 6.4.0)
good_job
google-apis-gmail_v1
googleauth
grape (~> 1.7.0)
Expand Down Expand Up @@ -1176,4 +1176,4 @@ RUBY VERSION
ruby 3.2.1p31

BUNDLED WITH
2.4.7
2.4.6
7 changes: 2 additions & 5 deletions app/workers/attachments/cleanup_uncontainered_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@
# See COPYRIGHT and LICENSE files for more details.
#++

class Attachments::CleanupUncontaineredJob < Cron::CronJob
class Attachments::CleanupUncontaineredJob < ApplicationJob
queue_with_priority :low

# runs at 10:03 pm
self.cron_expression = '03 22 * * *'

def perform
Attachment
.where(container: nil)
Expand All @@ -50,7 +47,7 @@ def too_old
attachment_table = Attachment.arel_table

attachment_table[:created_at]
.lteq(Time.now - OpenProject::Configuration.attachments_grace_period.minutes)
.lteq(Time.zone.now - OpenProject::Configuration.attachments_grace_period.minutes)
.to_sql
end
end
5 changes: 1 addition & 4 deletions app/workers/cron/clear_old_sessions_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@
#++

module Cron
class ClearOldSessionsJob < CronJob
class ClearOldSessionsJob < ApplicationJob
include ::RakeJob

# runs at 1:15 nightly
self.cron_expression = '15 1 * * *'

def perform
super 'db:sessions:expire', 7
end
Expand Down
5 changes: 1 addition & 4 deletions app/workers/cron/clear_tmp_cache_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@
#++

module Cron
class ClearTmpCacheJob < CronJob
class ClearTmpCacheJob < ApplicationJob
include ::RakeJob

# runs at 02:45 sundays
self.cron_expression = '45 2 * * 7'

def perform
super 'tmp:cache:clear'
end
Expand Down
5 changes: 1 addition & 4 deletions app/workers/cron/clear_uploaded_files_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@
#++

module Cron
class ClearUploadedFilesJob < CronJob
class ClearUploadedFilesJob < ApplicationJob
include ::RakeJob

# Runs 23pm fridays
self.cron_expression = '0 23 * * 5'

def perform
super 'attachments:clear'
end
Expand Down
76 changes: 0 additions & 76 deletions app/workers/cron/cron_job.rb

This file was deleted.

5 changes: 1 addition & 4 deletions app/workers/ldap/synchronization_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
#++

module Ldap
class SynchronizationJob < ::Cron::CronJob
# Run once per night at 11:30pm
self.cron_expression = '30 23 * * *'

class SynchronizationJob < ApplicationJob
def perform
run_user_sync
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,11 @@

module Notifications
# Creates date alert jobs for users whose local time is 1:00 am.
class ScheduleDateAlertsNotificationsJob < Cron::CronJob
# runs every quarter of an hour, so 00:00, 00:15,..., 15:30, 15:45, 16:00, ...
self.cron_expression = '*/15 * * * *'

class ScheduleDateAlertsNotificationsJob < ApplicationJob
def perform
return unless EnterpriseToken.allows_to?(:date_alerts)

service = Service.new(times_from_scheduled_to_execution)
service.call
Service.new(times_from_scheduled_to_execution).call
end

# Returns times from scheduled execution time to current time in 15 minutes
Expand Down
5 changes: 1 addition & 4 deletions app/workers/notifications/schedule_reminder_mails_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
#++

module Notifications
class ScheduleReminderMailsJob < Cron::CronJob
# runs every quarter of an hour, so 00:00, 00:15...
self.cron_expression = '*/15 * * * *'

class ScheduleReminderMailsJob < ApplicationJob
def perform
User.having_reminder_mail_to_send(run_at).pluck(:id).each do |user_id|
Mails::ReminderJob.perform_later(user_id)
Expand Down
5 changes: 1 addition & 4 deletions app/workers/oauth/cleanup_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@
#++

module OAuth
class CleanupJob < ::Cron::CronJob
class CleanupJob < ApplicationJob
include ::RakeJob

# runs at 1:52 nightly
self.cron_expression = '52 1 * * *'

queue_with_priority :low

def perform
Expand Down
5 changes: 1 addition & 4 deletions app/workers/paper_trail_audits/cleanup_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
#++

module PaperTrailAudits
class CleanupJob < ::Cron::CronJob
# runs at 4:03 on Saturday
self.cron_expression = '3 4 * * 6'

class CleanupJob < ApplicationJob
# Clean any paper trails older than 60 days
def perform
::PaperTrailAudit
Expand Down
5 changes: 0 additions & 5 deletions bin/delayed_job

This file was deleted.

14 changes: 12 additions & 2 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class Application < Rails::Application
# config.time_zone = 'Central Time (US & Canada)'

# Add locales from crowdin translations to i18n
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', 'crowdin', '*.{rb,yml}').to_s]
config.i18n.load_path += Dir[Rails.root.join("config/locales/crowdin/*.{rb,yml}").to_s]
config.i18n.default_locale = :en

# Fall back to default locale
Expand Down Expand Up @@ -219,7 +219,17 @@ class Application < Rails::Application
# This allows for setting the root either via config file or via environment variable.
config.action_controller.relative_url_root = OpenProject::Configuration['rails_relative_url_root']

config.active_job.queue_adapter = :delayed_job
config.active_job.queue_adapter = :good_job

config.good_job.preserve_job_records = true
config.good_job.retry_on_unhandled_error = false
# config.good_job.on_thread_error = -> (exception) { Rails.error.report(exception) }
config.good_job.execution_mode = :external
config.good_job.queues = '*'
config.good_job.max_threads = 20
config.good_job.poll_interval = 30
config.good_job.shutdown_timeout = 25
config.good_job.enable_cron = true

config.action_controller.asset_host = OpenProject::Configuration::AssetHost.value

Expand Down
47 changes: 36 additions & 11 deletions config/initializers/cronjobs.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,40 @@
# Register "Cron-like jobs"

OpenProject::Application.configure do |application|
application.config.to_prepare do
Cron::CronJob.register! Cron::ClearOldSessionsJob,
Cron::ClearTmpCacheJob,
Cron::ClearUploadedFilesJob,
OAuth::CleanupJob,
PaperTrailAudits::CleanupJob,
Attachments::CleanupUncontaineredJob,
Notifications::ScheduleDateAlertsNotificationsJob,
Notifications::ScheduleReminderMailsJob,
Ldap::SynchronizationJob
end
application.config.good_job.cron.merge!(
{
'Cron::ClearOldSessionsJob': {
cron: '15 1 * * *', # runs at 1:15 nightly
class: 'Cron::ClearOldSessionsJob'
},
'Cron::ClearTmpCacheJob': {
cron: '45 2 * * 7', # runs at 02:45 sundays
class: 'Cron::ClearTmpCacheJob'
},
'Cron::ClearUploadedFilesJob': {
cron: '0 23 * * 5', # runs 23:00 fridays
class: 'Cron::ClearUploadedFilesJob'
},
'OAuth::CleanupJob': {
cron: '52 1 * * *',
class: 'OAuth::CleanupJob'
},
'PaperTrailAudits::CleanupJob': {
cron: '3 4 * * 6',
class: 'PaperTrailAudits::CleanupJob'
},
'Attachments::CleanupUncontaineredJob': {
cron: '03 22 * * *', # runs at 10:03 pm
class: 'Attachments::CleanupUncontaineredJob'
},
'Notifications::ScheduleDateAlertsNotificationsJob': {
cron: '*/15 * * * *', # runs every 15th minute
class: 'Notifications::ScheduleDateAlertsNotificationsJob'
},
'Notifications::ScheduleReminderMailsJob': {
cron: '*/15 * * * *', # runs every 15th minute
class: 'Notifications::ScheduleReminderMailsJob'
}
}
)
end
28 changes: 28 additions & 0 deletions config/initializers/database_pool_size.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2023 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.
#++

config = Rails.env.production? && Rails.application.config.database_configuration[Rails.env]
pool_size = config && [OpenProject::Configuration.web_max_threads + 1, config['pool'].to_i].max

Expand Down
Loading

0 comments on commit ba43300

Please sign in to comment.