Skip to content

Instantly share code, notes, and snippets.

@pmatsinopoulos
Last active April 14, 2025 13:53
Show Gist options
  • Save pmatsinopoulos/3edd981a26b85a58fdd3e4f406cf933e to your computer and use it in GitHub Desktop.
Save pmatsinopoulos/3edd981a26b85a58fdd3e4f406cf933e to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
module EnqueueableJob
extend ActiveSupport::Concern
included do
def process_enqueued_job(queueable:)
enqueued_job = nil
ActiveRecord::Base.transaction do
AdvisoryLock.lock(
lock_namespace: queueable.queueable_lock_namespace,
lock_key: queueable.queueable_lock_key(job_class_name: self.class.name),
lock_comment: queueable.queueable_lock_comment(job_class_name: self.class.name)
)
enqueued_job = EnqueuedJob.where(
provider_job_id: [ provider_job_id, job_id ] # it seems that in +test+ env +provider_job_id+ is not present
).first
end
if enqueued_job.present?
yield instrumentation_payload
begin
enqueued_job.destroy!
rescue
nil
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment