Skip to content

Commit

Permalink
fix syntax for older ruby versions, fix rubocop offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
nduitz committed Jun 25, 2024
1 parent f4cc839 commit 7b1bf6a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
4 changes: 3 additions & 1 deletion lib/active_job/uniqueness/active_job_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def unlock!(*arguments)

private

delegate :validate_on_conflict_action!, :validate_on_redis_connection_error!, to: :'ActiveJob::Uniqueness.config'
delegate :validate_on_conflict_action!,
:validate_on_redis_connection_error!,
to: :'ActiveJob::Uniqueness.config'
end

included do
Expand Down
3 changes: 1 addition & 2 deletions lib/active_job/uniqueness/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ def validate_on_conflict_action!(action)
raise ActiveJob::Uniqueness::InvalidOnConflictAction, "Unexpected '#{action}' action on conflict"
end


def on_redis_connection_error=(action)
validate_on_redis_connection_error!(action)

config.on_redis_connection_error = action
end

def validate_on_redis_connection_error!(action)
return if action.nil? || :raise == action || action.respond_to?(:call)
return if action.nil? || action == :raise || action.respond_to?(:call)

raise ActiveJob::Uniqueness::InvalidOnConflictAction, "Unexpected '#{action}' action on_redis_connection_error"
end
Expand Down
4 changes: 2 additions & 2 deletions lib/active_job/uniqueness/sidekiq_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def remove_job
module ScheduledSet
def delete(score, job_id)
entry = find_job(job_id)
ActiveJob::Uniqueness.unlock_sidekiq_job!(entry.item) if super(score, job_id)
ActiveJob::Uniqueness.unlock_sidekiq_job!(entry.item) if super
entry
end
end
Expand All @@ -67,7 +67,7 @@ def clear
end

def delete_by_value(name, value)
ActiveJob::Uniqueness.unlock_sidekiq_job!(Sidekiq.load_json(value)) if super(name, value)
ActiveJob::Uniqueness.unlock_sidekiq_job!(Sidekiq.load_json(value)) if super
end
end
end
Expand Down
15 changes: 6 additions & 9 deletions lib/active_job/uniqueness/strategies/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,14 @@ def after_perform

module LockingOnEnqueue
def before_enqueue

case lock(resource: lock_key, ttl: lock_ttl)
in [:handle_redis_connection_error, error]
handle_redis_connection_error(resource: lock_key, on_redis_connection_error: on_redis_connection_error, error: error)
when [:handle_redis_connection_error, error]
handle_redis_connection_error(resource: lock_key, on_redis_connection_error: on_redis_connection_error,
error: error)
abort_job
in nil | false
when nil, false
handle_conflict(resource: lock_key, on_conflict: on_conflict)
abort_job
else
return
end
end

Expand Down Expand Up @@ -98,10 +96,9 @@ def handle_conflict(on_conflict:, resource:, event: :conflict)

def handle_redis_connection_error(resource:, on_redis_connection_error:, error:)
case on_redis_connection_error
when :raise then raise error
when nil then raise error
when :raise, nil then raise error
else
on_redis_connection_error.call(job, resource:, error:)
on_redis_connection_error.call(job, resource: resource, error: error)
end
end

Expand Down

0 comments on commit 7b1bf6a

Please sign in to comment.