Skip to content

Commit

Permalink
Add logging of Que jobs skipped in migration
Browse files Browse the repository at this point in the history
  • Loading branch information
yulgolem committed Apr 12, 2021
1 parent 83706a7 commit 687196b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
23 changes: 15 additions & 8 deletions db/data/20210405081552_migrate_que_jobs.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
class MigrateQueJobs < ActiveRecord::Migration[6.0]
def up
QueJob.all.each do |job|
next if job.last_error.present?

klass = job.job_class.constantize
next unless klass < ApplicationJob

args = job.args
klass.perform_later(args)
if skip_condition(job)
logger.info "Skipped Que job migration: #{job.inspect}"
else
args = job.args
job.job_class.constantize.perform_later(args)
end
end
end

def down
raise ActiveRecord::IrreversibleMigration
# raise ActiveRecord::IrreversibleMigration
end

def logger
@logger ||= Logger.new(Rails.root.join('log', 'que_to_sidekiq_migration.log'))
end

def skip_condition(job)
job.last_error.present? || !(job.job_class.constantize < ApplicationJob)
end
end
2 changes: 1 addition & 1 deletion db/data_schema.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# encoding: UTF-8
DataMigrate::Data.define(version: 20210407140317)
DataMigrate::Data.define(version: 20210405081552)

0 comments on commit 687196b

Please sign in to comment.