Skip to content

Commit

Permalink
Merge pull request #74 from shahidkhaliq/fix-modules
Browse files Browse the repository at this point in the history
Fix log subscriber
  • Loading branch information
sharshenov authored Aug 16, 2024
2 parents e376253 + 1a04df6 commit b985597
Showing 1 changed file with 68 additions and 66 deletions.
134 changes: 68 additions & 66 deletions lib/active_job/uniqueness/log_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,98 +3,100 @@
require 'active_support/log_subscriber'

module ActiveJob
class LogSubscriber < ActiveSupport::LogSubscriber # :nodoc:
def lock(event)
job = event.payload[:job]
resource = event.payload[:resource]

debug do
"Locked #{lock_info(job, resource)}" + args_info(job)
module Uniqueness
class LogSubscriber < ActiveSupport::LogSubscriber # :nodoc:
def lock(event)
job = event.payload[:job]
resource = event.payload[:resource]

debug do
"Locked #{lock_info(job, resource)}" + args_info(job)
end
end
end

def runtime_lock(event)
job = event.payload[:job]
resource = event.payload[:resource]
def runtime_lock(event)
job = event.payload[:job]
resource = event.payload[:resource]

debug do
"Locked runtime #{lock_info(job, resource)}" + args_info(job)
debug do
"Locked runtime #{lock_info(job, resource)}" + args_info(job)
end
end
end

def unlock(event)
job = event.payload[:job]
resource = event.payload[:resource]
def unlock(event)
job = event.payload[:job]
resource = event.payload[:resource]

debug do
"Unlocked #{lock_info(job, resource)}"
debug do
"Unlocked #{lock_info(job, resource)}"
end
end
end

def runtime_unlock(event)
job = event.payload[:job]
resource = event.payload[:resource]
def runtime_unlock(event)
job = event.payload[:job]
resource = event.payload[:resource]

debug do
"Unlocked runtime #{lock_info(job, resource)}"
debug do
"Unlocked runtime #{lock_info(job, resource)}"
end
end
end

def conflict(event)
job = event.payload[:job]
resource = event.payload[:resource]
def conflict(event)
job = event.payload[:job]
resource = event.payload[:resource]

info do
"Not unique #{lock_info(job, resource)}" + args_info(job)
info do
"Not unique #{lock_info(job, resource)}" + args_info(job)
end
end
end

def runtime_conflict(event)
job = event.payload[:job]
resource = event.payload[:resource]
def runtime_conflict(event)
job = event.payload[:job]
resource = event.payload[:resource]

info do
"Not unique runtime #{lock_info(job, resource)}" + args_info(job)
info do
"Not unique runtime #{lock_info(job, resource)}" + args_info(job)
end
end
end

private
private

def lock_info(job, resource)
"#{job.class.name} (Job ID: #{job.job_id}) (Lock key: #{resource})"
end
def lock_info(job, resource)
"#{job.class.name} (Job ID: #{job.job_id}) (Lock key: #{resource})"
end

def args_info(job)
if job.arguments.any? && log_arguments?(job)
" with arguments: #{job.arguments.map { |arg| format(arg).inspect }.join(', ')}"
else
''
def args_info(job)
if job.arguments.any? && log_arguments?(job)
" with arguments: #{job.arguments.map { |arg| format(arg).inspect }.join(', ')}"
else
''
end
end
end

def log_arguments?(job)
return true unless job.class.respond_to?(:log_arguments?)
def log_arguments?(job)
return true unless job.class.respond_to?(:log_arguments?)

job.class.log_arguments?
end
job.class.log_arguments?
end

def format(arg)
case arg
when Hash
arg.transform_values { |value| format(value) }
when Array
arg.map { |value| format(value) }
when GlobalID::Identification
arg.to_global_id rescue arg
else
arg
def format(arg)
case arg
when Hash
arg.transform_values { |value| format(value) }
when Array
arg.map { |value| format(value) }
when GlobalID::Identification
arg.to_global_id rescue arg
else
arg
end
end
end

def logger
ActiveJob::Base.logger
def logger
ActiveJob::Base.logger
end
end
end
end

ActiveJob::LogSubscriber.attach_to :active_job_uniqueness
ActiveJob::Uniqueness::LogSubscriber.attach_to :active_job_uniqueness

0 comments on commit b985597

Please sign in to comment.