trabajo-afectivo/config/initializers/delayed_jobs_ensure_active_job_lock_removal.rb

32 lines
963 B
Ruby
Raw Permalink Normal View History

2022-01-01 13:38:12 +00:00
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
require 'delayed_job'
module Delayed
class Job < ::ActiveRecord::Base
after_destroy :remove_active_job_lock
def remove_active_job_lock
# only ActiveJob Delayed::Jobs can have a lock
return if !payload_object.is_a?(::ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper)
# deserialize ActiveJob and load it's arguments to generate the lock_key
active_job = ::ActiveJob::Base.deserialize(payload_object.job_data)
# ActiveJob that is not an HasActiveJobLock has no lock
return if !active_job.is_a?(HasActiveJobLock)
begin
active_job.arguments = ::ActiveJob::Arguments.deserialize(active_job.instance_variable_get(:@serialized_arguments))
rescue => e
active_job.arguments = nil
Rails.logger.error e
end
# remove possible lock
active_job.release_active_job_lock!
end
end
end