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

Migrate 'in queue' jobs to good_jobs table.

Pavel Balashouc69d5eb03d21
diff --git a/Gemfile b/Gemfile
index 629cb0e8879..6174cbae775 100644
--- a/Gemfile
+++ b/Gemfile
@@ -124,7 +124,8 @@ gem 'multi_json', '~> 1.15.0'
gem 'oj', '~> 3.16.0'
gem 'daemons'
-gem 'good_job'
+gem 'delayed_job', require: false # only needed for ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper to be available in db/migrate/20240227154544_remove_delayed_jobs.rb
+gem 'good_job', '~> 3.26.1' # update should be done manually in sync with saas-openproject version.
gem 'rack-protection', '~> 3.2.0'
diff --git a/Gemfile.lock b/Gemfile.lock
index 6840e70bdc1..ae94811ef53 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -445,6 +445,8 @@ GEM
deckar01-task_list (2.3.4)
html-pipeline (~> 2.0)
declarative (0.0.20)
+ delayed_job (4.1.11)
+ activesupport (>= 3.0, < 8.0)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
diff-lcs (1.5.1)
@@ -543,7 +545,7 @@ GEM
friendly_id (5.5.1)
activerecord (>= 4.0.0)
front_matter_parser (1.0.1)
- fugit (1.9.0)
+ fugit (1.10.1)
et-orbi (~> 1, >= 1.2.7)
raabro (~> 1.4)
fuubar (2.5.1)
@@ -557,7 +559,7 @@ GEM
i18n (>= 0.7)
multi_json
request_store (>= 1.0)
- good_job (3.21.5)
+ good_job (3.26.1)
activejob (>= 6.0.0)
activerecord (>= 6.0.0)
concurrent-ruby (>= 1.0.2)
@@ -1160,6 +1162,7 @@ DEPENDENCIES
date_validator (~> 0.12.0)
debug
deckar01-task_list (~> 2.3.1)
+ delayed_job
disposable (~> 0.6.2)
doorkeeper (~> 5.6.6)
dotenv-rails
@@ -1177,7 +1180,7 @@ DEPENDENCIES
friendly_id (~> 5.5.0)
fuubar (~> 2.5.0)
gon (~> 6.4.0)
- good_job
+ good_job (~> 3.26.1)
google-apis-gmail_v1
googleauth
grape (~> 2.0.0)
diff --git a/db/migrate/20240227154544_remove_delayed_jobs.rb b/db/migrate/20240227154544_remove_delayed_jobs.rb
index ea929b73d4e..bff7e2421e8 100644
--- a/db/migrate/20240227154544_remove_delayed_jobs.rb
+++ b/db/migrate/20240227154544_remove_delayed_jobs.rb
@@ -28,6 +28,35 @@
class RemoveDelayedJobs < ActiveRecord::Migration[7.1]
def change
+ reversible do |direction|
+ direction.up do
+ tuples = execute <<~SQL
+ select * from delayed_jobs
+ where locked_by is null -- not in progress
+ and handler NOT LIKE '%job_class: Storages::ManageNextcloudIntegrationEventsJob%' -- no need to migrate. It will be run later with cron.
+ and cron is null; -- not cron scheduled
+ SQL
+ tuples.each do |tuple|
+ job_data = YAML.load(tuple['handler'],
+ permitted_classes: [ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper])
+ .job_data
+ new_uuid = SecureRandom.uuid
+ good_job_record = GoodJob::BaseExecution.new
+ good_job_record.id = new_uuid
+ good_job_record.serialized_params = job_data
+ good_job_record.serialized_params['job_id'] = new_uuid
+ good_job_record.queue_name = job_data['queue_name']
+ good_job_record.priority = job_data['priority']
+ good_job_record.scheduled_at = job_data['scheduled_at']
+ good_job_record.active_job_id = new_uuid
+ good_job_record.concurrency_key = nil
+ good_job_record.job_class = job_data['job_class']
+ good_job_record.save!
+ end
+ end
+ direction.down {}
+ end
+
drop_table :delayed_jobs do |t|
t.integer :priority, default: 0 # Allows some jobs to jump to the front of the queue
t.integer :attempts, default: 0 # Provides for retries, but still fail eventually.