Add logging of Que jobs skipped in migration

This commit is contained in:
Alex Sherman 2021-04-12 17:03:30 +05:00
parent 83706a78e3
commit 687196baed
2 changed files with 16 additions and 9 deletions

View file

@ -1,17 +1,24 @@
class MigrateQueJobs < ActiveRecord::Migration[6.0] class MigrateQueJobs < ActiveRecord::Migration[6.0]
def up def up
QueJob.all.each do |job| QueJob.all.each do |job|
next if job.last_error.present? if skip_condition(job)
logger.info "Skipped Que job migration: #{job.inspect}"
klass = job.job_class.constantize else
next unless klass < ApplicationJob
args = job.args args = job.args
klass.perform_later(args) job.job_class.constantize.perform_later(args)
end
end end
end end
def down 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
end end

View file

@ -1,2 +1,2 @@
# encoding: UTF-8 # encoding: UTF-8
DataMigrate::Data.define(version: 20210407140317) DataMigrate::Data.define(version: 20210405081552)