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 Feb 3, 2024
1 parent b28c567 commit 8534396
Show file tree
Hide file tree
Showing 72 changed files with 786 additions and 1,334 deletions.
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,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.2.0'

Expand Down
17 changes: 8 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -456,13 +456,6 @@ GEM
deckar01-task_list (2.3.3)
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.8)
activerecord (>= 3.0, < 8.0)
delayed_job (>= 3.0, < 5)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
diff-lcs (1.5.0)
Expand Down Expand Up @@ -576,6 +569,13 @@ GEM
i18n (>= 0.7)
multi_json
request_store (>= 1.0)
good_job (3.21.5)
activejob (>= 6.0.0)
activerecord (>= 6.0.0)
concurrent-ruby (>= 1.0.2)
fugit (>= 1.1)
railties (>= 6.0.0)
thor (>= 0.14.1)
google-apis-core (0.13.0)
addressable (~> 2.5, >= 2.5.1)
googleauth (~> 1.9)
Expand Down Expand Up @@ -1158,8 +1158,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 @@ -1177,6 +1175,7 @@ DEPENDENCIES
friendly_id (~> 5.5.0)
fuubar (~> 2.5.0)
gon (~> 6.4.0)
good_job
google-apis-gmail_v1
googleauth
grape (~> 2.0.0)
Expand Down
5 changes: 4 additions & 1 deletion app/contracts/settings/working_days_params_contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ def working_days_are_present
end
end

# TODO: consider implementing using GoodJob concurrency control mechanisms
def unique_job
if WorkPackages::ApplyWorkingDaysChangeJob.scheduled?
if GoodJob::Job
.where(finished_at: nil)
.exists?(job_class: 'WorkPackages::ApplyWorkingDaysChangeJob')
errors.add :base, :previous_working_day_changes_unprocessed
end
end
Expand Down
6 changes: 3 additions & 3 deletions app/seeders/root_seeder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ def prepare_seed!
ActionMailer::Base.perform_deliveries = false

# Avoid asynchronous DeliverWorkPackageCreatedJob
previous_delay_jobs = Delayed::Worker.delay_jobs
Delayed::Worker.delay_jobs = false
previous_execution_mode = Rails.configuration.good_job.execution_mode
Rails.configuration.good_job.execution_mode = :inline

yield
ensure
ActionMailer::Base.perform_deliveries = previous_perform_deliveries
Delayed::Worker.delay_jobs = previous_delay_jobs
Rails.configuration.good_job.execution_mode = previous_execution_mode
end

def seed_basic_data
Expand Down
5 changes: 5 additions & 0 deletions app/workers/application_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ def reload_mailer_settings!
Setting.reload_mailer_settings!
end

def good_job_scheduled_at
GoodJob::Job.where(id: job_id)
.pick(:scheduled_at)
end

private

def prepare_job_context
Expand Down
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
41 changes: 0 additions & 41 deletions app/workers/concerns/scheduled_job.rb

This file was deleted.

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 All @@ -57,7 +53,7 @@ def times_from_scheduled_to_execution
end

def scheduled_time
self.class.delayed_job.run_at.then { |t| t.change(min: t.min / 15 * 15) }
good_job_scheduled_at.then { |t| t.change(min: t.min / 15 * 15) }
end
end
end
13 changes: 4 additions & 9 deletions app/workers/notifications/schedule_reminder_mails_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,13 @@
#++

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|
User.having_reminder_mail_to_send(good_job_scheduled_at)
.pluck(:id)
.each do |user_id|
Mails::ReminderJob.perform_later(user_id)
end
end

def run_at
self.class.delayed_job.run_at
end
end
end
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
1 change: 0 additions & 1 deletion app/workers/work_packages/apply_working_days_change_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

class WorkPackages::ApplyWorkingDaysChangeJob < ApplicationJob
queue_with_priority :above_normal
include ::ScheduledJob

def perform(user_id:, previous_working_days:, previous_non_working_days:)
user = User.find(user_id)
Expand Down
5 changes: 0 additions & 5 deletions bin/delayed_job

This file was deleted.

Loading

0 comments on commit 8534396

Please sign in to comment.