Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 12 additions & 26 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
inherit_gem:
rubocop-mhenrixon:
- config/default.yml

require:
plugins:
- rubocop-performance
- rubocop-rake
- rubocop-rspec
- rubocop-thread_safety

AllCops:
NewCops: enable
TargetRubyVersion: 2.7
Include:
- "examples/**/*.rb"
- "*.rb"
- "**/examples/**/*.rb"
- "**/*.rb"
Exclude:
- "**/*.erb"
- "**/.DS_Store"
Expand All @@ -27,6 +24,7 @@ AllCops:
- "myapp/**/*"
- "Sidekiq/**/*"
- "vendor/**/*"

Layout/ArgumentAlignment:
Enabled: true
EnforcedStyle: with_fixed_indentation
Expand Down Expand Up @@ -65,22 +63,8 @@ Lint/SuppressedException:
Lint/UselessAssignment:
Enabled: true

Metrics/AbcSize:
Max: 38

Metrics/CyclomaticComplexity:
Max: 7

Metrics/BlockLength:
Enabled: true
Exclude:
- "**/spec/**/*.rb"
- "**/*.rake"
- "Rakefile"
- "*.gemspec"

Metrics/PerceivedComplexity:
Max: 8
Metrics:
Enabled: false

Naming/AccessorMethodName:
Enabled: true
Expand Down Expand Up @@ -162,8 +146,9 @@ RSpec/RepeatedExample:
Style/Documentation:
Enabled: true
Exclude:
- "examples/**/*.rb"
- "bin/**/*.rb"
- "examples/**/*"
- "bin/**/*"
- "spec/**/*"
- "lib/sidekiq_unique_jobs/testing.rb"
- "lib/sidekiq_unique_jobs/core_ext.rb"
- "lib/sidekiq_unique_jobs/sidekiq_unique_ext.rb"
Expand Down Expand Up @@ -207,7 +192,8 @@ Style/GlobalVars:
Style/ModuleFunction:
Enabled: false

ThreadSafety/InstanceVariableInClassMethod:
ThreadSafety/ClassInstanceVariable:
Exclude:
- lib/sidekiq_unique_jobs/web.rb
- lib/sidekiq_unique_jobs/web.rb

6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ gem "rspec"
gem "rspec-benchmark"
gem "rspec-html-matchers"
gem "rspec-its"
gem "rubocop-mhenrixon"
gem "rubocop"
gem "rubocop-performance"
gem "rubocop-rake"
gem "rubocop-rspec"
gem "rubocop-thread_safety"
gem "simplecov-sublime", ">= 0.21.2", require: false
gem "sinatra"
gem "timecop"
Expand Down
4 changes: 2 additions & 2 deletions lib/sidekiq_unique_jobs/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Cli < Thor
# :nodoc:
# rubocop:disable Style/OptionalBooleanParameter
def self.banner(command, _namespace = nil, _subcommand = false) # rubocop:disable Style/OptionalBooleanParameter
"jobs #{@package_name} #{command.usage}" # rubocop:disable ThreadSafety/InstanceVariableInClassMethod
"jobs #{@package_name} #{command.usage}" # rubocop:disable ThreadSafety/ClassInstanceVariable
end
# rubocop:enable Style/OptionalBooleanParameter

Expand Down Expand Up @@ -51,7 +51,7 @@ def console
console_class.start
end

no_commands do # rubocop:disable Metrics/BlockLength
no_commands do
# :nodoc:
def digests
@digests ||= SidekiqUniqueJobs::Digests.new
Expand Down
3 changes: 1 addition & 2 deletions lib/sidekiq_unique_jobs/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ module SidekiqUniqueJobs
# Shared class for dealing with gem configuration
#
# @author Mauro Berlanda <[email protected]>
# rubocop:disable Metrics/ClassLength
class Config < ThreadSafeConfig
#
# @return [Hash<Symbol, SidekiqUniqueJobs::Lock::BaseLock] all available queued locks
Expand Down Expand Up @@ -181,7 +180,7 @@ class Config < ThreadSafeConfig
#
# @return [SidekiqUniqueJobs::Config] a default configuration
#
def self.default # rubocop:disable Metrics/MethodLength
def self.default
new(
LOCK_TIMEOUT,
LOCK_TTL,
Expand Down
2 changes: 1 addition & 1 deletion lib/sidekiq_unique_jobs/lock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module SidekiqUniqueJobs
#
# @author Mikael Henriksson <[email protected]>
#
class Lock # rubocop:disable Metrics/ClassLength
class Lock
# includes "SidekiqUniqueJobs::Connection"
# @!parse include SidekiqUniqueJobs::Connection
include SidekiqUniqueJobs::Connection
Expand Down
4 changes: 2 additions & 2 deletions lib/sidekiq_unique_jobs/locksmith.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module SidekiqUniqueJobs
# Lock manager class that handles all the various locks
#
# @author Mikael Henriksson <[email protected]>
class Locksmith # rubocop:disable Metrics/ClassLength
class Locksmith
# includes "SidekiqUniqueJobs::Connection"
# @!parse include SidekiqUniqueJobs::Connection
include SidekiqUniqueJobs::Connection
Expand Down Expand Up @@ -243,7 +243,7 @@ def enqueue(conn)
# @return [nil] when lock was not possible
# @return [Object] whatever the block returns when lock was acquired
#
def primed_async(conn, wait = nil, &block) # rubocop:disable Metrics/MethodLength
def primed_async(conn, wait = nil, &block)
timeout = (wait || config.timeout).to_i
timeout = 1 if timeout.zero?

Expand Down
5 changes: 2 additions & 3 deletions lib/sidekiq_unique_jobs/orphans/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ module Manager
#
# @return [SidekiqUniqueJobs::TimerTask] the task that was started
#
# rubocop:disable
def start(test_task = nil)
return if disabled?
return if registered?
Expand Down Expand Up @@ -74,7 +73,7 @@ def stop
# @return [<type>] <description>
#
def task
@task ||= default_task # rubocop:disable ThreadSafety/InstanceVariableInClassMethod
@task ||= default_task # rubocop:disable ThreadSafety/ClassInstanceVariable
end

#
Expand Down Expand Up @@ -102,7 +101,7 @@ def default_task
# @return [void]
#
def task=(task)
@task = task # rubocop:disable ThreadSafety/InstanceVariableInClassMethod
@task = task # rubocop:disable ThreadSafety/ClassInstanceVariable
end

#
Expand Down
7 changes: 3 additions & 4 deletions lib/sidekiq_unique_jobs/orphans/ruby_reaper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module Orphans
#
# @author Mikael Henriksson <[email protected]>
#
# rubocop:disable Metrics/ClassLength
class RubyReaper < Reaper
include SidekiqUniqueJobs::Timing

Expand Down Expand Up @@ -107,7 +106,7 @@ def max_score
#
# @return [Array<String>] an array of orphaned digests
#
def orphans # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
def orphans
orphans = []
page = 0
per = reaper_count * 2
Expand Down Expand Up @@ -197,7 +196,7 @@ def enqueued?(digest)
end
end

def active?(digest) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def active?(digest)
Sidekiq.redis do |conn|
procs = conn.sscan("processes").to_a
return false if procs.empty?
Expand Down Expand Up @@ -253,7 +252,7 @@ def queues(conn, &block)
conn.sscan("queues").each(&block)
end

def entries(conn, queue, &block) # rubocop:disable Metrics/MethodLength
def entries(conn, queue, &block)
queue_key = "queue:#{queue}"
initial_size = conn.llen(queue_key)
deleted_size = 0
Expand Down
2 changes: 1 addition & 1 deletion lib/sidekiq_unique_jobs/reflections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def initialize
#
# @return [void] <description>
#
def dispatch(reflection, *args) # rubocop:disable Metrics/MethodLength
def dispatch(reflection, *args)
if (block = @reflections[reflection])
block.call(*args)

Expand Down
8 changes: 4 additions & 4 deletions lib/sidekiq_unique_jobs/sidekiq_unique_jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Contains configuration and utility methods that belongs top level
#
# @author Mikael Henriksson <[email protected]>
module SidekiqUniqueJobs # rubocop:disable Metrics/ModuleLength
module SidekiqUniqueJobs
include SidekiqUniqueJobs::Connection
extend SidekiqUniqueJobs::JSON

Expand All @@ -17,7 +17,7 @@ module SidekiqUniqueJobs # rubocop:disable Metrics/ModuleLength
# @return [SidekiqUniqueJobs::Config] the gem configuration
#
def config
@config ||= reset! # rubocop:disable ThreadSafety/InstanceVariableInClassMethod
@config ||= reset! # rubocop:disable ThreadSafety/ClassInstanceVariable
end

#
Expand Down Expand Up @@ -108,7 +108,7 @@ def use_config(tmp_config = {})
# @return [SidekiqUniqueJobs::Config] a default gem configuration
#
def reset!
@config = SidekiqUniqueJobs::Config.default # rubocop:disable ThreadSafety/InstanceVariableInClassMethod
@config = SidekiqUniqueJobs::Config.default # rubocop:disable ThreadSafety/ClassInstanceVariable
end

#
Expand Down Expand Up @@ -288,7 +288,7 @@ def safe_constantize(str)
# @return [Reflections]
#
def reflections
@reflections ||= Reflections.new # rubocop:disable ThreadSafety/InstanceVariableInClassMethod
@reflections ||= Reflections.new # rubocop:disable ThreadSafety/ClassInstanceVariable
end

#
Expand Down
2 changes: 1 addition & 1 deletion lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def job_class=(obj)

# The hook to call after a successful unlock
# @return [Proc]
def after_unlock_hook # rubocop:disable Metrics/MethodLength
def after_unlock_hook
lambda do
if @original_job_class.respond_to?(:after_unlock)
# instance method in sidekiq v6
Expand Down
2 changes: 1 addition & 1 deletion lib/sidekiq_unique_jobs/testing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Sidekiq
#
# @param [Hash<Symbol, Object>] tmp_config the temporary config to use
#
def self.use_options(tmp_config = {}) # rubocop:disable Metrics/MethodLength
def self.use_options(tmp_config = {})
if respond_to?(:default_job_options)
default_job_options.clear
self.default_job_options = tmp_config
Expand Down
20 changes: 12 additions & 8 deletions lib/sidekiq_unique_jobs/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module SidekiqUniqueJobs
# Useful for deleting keys that for whatever reason wasn't deleted
# @author Mikael Henriksson <[email protected]>
module Web
def self.registered(app) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def self.registered(app)
app.helpers Web::Helpers

app.get "/changelogs" do
Expand All @@ -19,7 +19,7 @@ def self.registered(app) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
@total_size, @next_cursor, @changelogs = changelog.page(
cursor: @current_cursor,
pattern: @filter,
page_size: @count
page_size: @count,
)

erb(unique_template(:changelogs))
Expand All @@ -40,7 +40,7 @@ def self.registered(app) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
@total_size, @next_cursor, @locks = digests.page(
cursor: @current_cursor,
pattern: @filter,
page_size: @count
page_size: @count,
)

erb(unique_template(:locks))
Expand All @@ -56,7 +56,7 @@ def self.registered(app) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
@total_size, @next_cursor, @locks = expiring_digests.page(
cursor: @current_cursor,
pattern: @filter,
page_size: @count
page_size: @count,
)

erb(unique_template(:locks))
Expand Down Expand Up @@ -99,15 +99,19 @@ def self.registered(app) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize

if Sidekiq::MAJOR >= 8
Sidekiq::Web.configure do |config|
config.register_extension(SidekiqUniqueJobs::Web, name: "unique_jobs", tab: ["Locks", "Expiring Locks", "Changelogs"],
index: %w[locks/ expiring_locks/ changelogs/])
config.register_extension(
SidekiqUniqueJobs::Web,
name: "unique_jobs",
tab: ["Locks", "Expiring Locks", "Changelogs"],
index: %w[locks/ expiring_locks/ changelogs/],
)
end
else
Sidekiq::Web.register(SidekiqUniqueJobs::Web)
Sidekiq::Web.tabs["Locks"] = "locks"
Sidekiq::Web.tabs["Expiring Locks"] = "expiring_locks"
Sidekiq::Web.tabs["Changelogs"] = "changelogs"
end
rescue NameError, LoadError => e
SidekiqUniqueJobs.logger.error(e)
rescue NameError, LoadError => ex
SidekiqUniqueJobs.logger.error(ex)
end
12 changes: 10 additions & 2 deletions lib/sidekiq_unique_jobs/web/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ def parse_time(time)
def safe_url_params(key)
return url_params(key) if Sidekiq::MAJOR >= 8

warn { "URL parameter `#{key}` should be accessed via String, not Symbol (at #{caller(3..3).first})" } if key.is_a?(Symbol)
if key.is_a?(Symbol)
warn do
"URL parameter `#{key}` should be accessed via String, not Symbol (at #{caller(3..3).first})"
end
end
request.params[key.to_s]
end

Expand All @@ -187,7 +191,11 @@ def safe_url_params(key)
def safe_route_params(key)
return route_params(key) if Sidekiq::MAJOR >= 8

warn { "Route parameter `#{key}` should be accessed via Symbol, not String (at #{caller(3..3).first})" } if key.is_a?(String)
if key.is_a?(String)
warn do
"Route parameter `#{key}` should be accessed via Symbol, not String (at #{caller(3..3).first})"
end
end
env["rack.route_params"][key.to_sym]
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/sidekiq_unique_jobs/changelog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
message: "Added from test",
job_id: job_id,
digest: digest,
script: __FILE__.to_s,
script: __FILE__,
}
end

Expand All @@ -33,7 +33,7 @@
message: "Added from test",
job_id: job_id,
digest: digest,
script: __FILE__.to_s,
script: __FILE__,
)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/sidekiq_unique_jobs/lock_args_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
SidekiqUniqueJobs::InvalidUniqueArguments,
a_string_starting_with(
'UniqueJobWithoutUniqueArgsParameter#unique_args takes 0 arguments, ' \
'received ["name", 2, {"whatever"=>nil, "type"=>"test"}]', \
'received ["name", 2, {"whatever"=>nil, "type"=>"test"}]',
),
)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/sidekiq_unique_jobs/logging_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def self.with_context(_msg)
end

context "when logger does not support context" do
let(:logger) { Logger.new("/dev/null") }
let(:logger) { Logger.new(File::NULL) }
let(:logging_context) { { "fuu" => "bar" } }

before do
Expand Down
Loading