sidekiq-unique-jobs 5.0.9 → 5.0.10

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sidekiq-unique-jobs might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7238f6463cf70d3aa15dfa9f13222bfd095be565
4
- data.tar.gz: 296c50852200e0fe7f17bef756aa4ed339764c9a
3
+ metadata.gz: 53332a20911a2add535139974709245c03425d86
4
+ data.tar.gz: f9b4bd20a09320b593f5e6d30ad7c10b1e8868de
5
5
  SHA512:
6
- metadata.gz: f3b1d70cb51300b90ed59fc873af2a1722b1775aaea2b077ae9df7b606ebee594bbd8b6ef75611b0ad90ecf7bad7968dd7e05fbbf3c32ffc8bdaac707451f403
7
- data.tar.gz: a1ab235a39e48aae97df51df2f912b832008ace438903eca2f386221c7c32d02a361af2f8eadf33aa4bd5702db1d6a094e7c522e1a00d864c5c334302b2344af
6
+ metadata.gz: b2164f8cd400bb144f5f6fd562177703ef935d55b9310d38dd94a29fd4e514748fdb50e57a5d690f2803c7a58392c534bf5900277af675764242435e53453e82
7
+ data.tar.gz: 71368b0d324404d60a1ebfc217dc417e7a70e233da312005184030089361c8f9755032f42f256bde1e31c4d6f5a1ec3873e4120af961cb0da1179bf81bc3a882
@@ -8,7 +8,7 @@ cache: bundler
8
8
  services:
9
9
  - redis-server
10
10
  script:
11
- - if [[ "${STYLE}" = "true" ]]; then bundle exec rubocop; fi;
11
+ - if [[ "${STYLE}" = "true" ]]; then bundle exec rubocop - P; fi;
12
12
  - bundle exec rspec spec
13
13
  - if [[ "${STYLE}" = "true" ]]; then CODECLIMATE_REPO_TOKEN=88e524e8f638efe690def7a6e2c72b1a9db5cdfa74548921b734d609a5858ee5 bundle exec codeclimate-test-reporter; fi;
14
14
  rvm:
@@ -1,3 +1,11 @@
1
+ ## v5.0.10
2
+
3
+ - Cleans up test setup and make tests more readable
4
+ - Allow raising all errors
5
+ - Log previously hidden errors
6
+ - Revert the changes of v5.0.5 (8a4b7648b8b0ee5d7dc1f5f5a036f41d52ad9a42)
7
+ - Allow name errors in unique args method to be raised
8
+
1
9
  ## v5.0.9
2
10
  - [#229](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/#229) Use HSCAN for expiring keys
3
11
  - [#232](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/#232) Fix testing helper
@@ -29,6 +29,7 @@ module SidekiqUniqueJobs
29
29
  default_run_lock_expiration: 60,
30
30
  default_lock: :while_executing,
31
31
  redis_test_mode: :redis, # :mock
32
+ raise_unique_args_errors: false,
32
33
  )
33
34
  end
34
35
 
@@ -55,12 +56,19 @@ module SidekiqUniqueJobs
55
56
  end
56
57
 
57
58
  # Attempt to constantize a string worker_class argument, always
58
- # failing back to the original argument.
59
+ # failing back to the original argument when the constant can't be found
60
+ #
61
+ # raises an error for other errors
59
62
  def worker_class_constantize(worker_class)
60
63
  return worker_class unless worker_class.is_a?(String)
61
64
  Object.const_get(worker_class)
62
- rescue NameError
63
- worker_class
65
+ rescue NameError => ex
66
+ case ex.message
67
+ when /uninitialized constant/
68
+ worker_class
69
+ else
70
+ raise
71
+ end
64
72
  end
65
73
 
66
74
  def mocked?
@@ -44,18 +44,18 @@ module SidekiqUniqueJobs
44
44
  console_class.start
45
45
  end
46
46
 
47
- private
48
-
49
- def logger
50
- SidekiqUniqueJobs.logger
51
- end
52
-
53
- def console_class
54
- require 'pry'
55
- Pry
56
- rescue LoadError
57
- require 'irb'
58
- IRB
47
+ no_commands do
48
+ def logger
49
+ SidekiqUniqueJobs.logger
50
+ end
51
+
52
+ def console_class
53
+ require 'pry'
54
+ Pry
55
+ rescue LoadError
56
+ require 'irb'
57
+ IRB
58
+ end
59
59
  end
60
60
  end
61
61
  end
@@ -3,8 +3,6 @@
3
3
  module SidekiqUniqueJobs
4
4
  module Lock
5
5
  class WhileExecuting
6
- MUTEX = Mutex.new
7
-
8
6
  def self.synchronize(item, redis_pool = nil)
9
7
  new(item, redis_pool).synchronize { yield }
10
8
  end
@@ -13,19 +11,19 @@ module SidekiqUniqueJobs
13
11
  @item = item
14
12
  @redis_pool = redis_pool
15
13
  @unique_digest = "#{create_digest}:run"
14
+ @mutex = Mutex.new
16
15
  end
17
16
 
18
17
  def synchronize
19
- MUTEX.lock
20
- sleep 0.1 until locked?
21
-
22
- yield
18
+ @mutex.synchronize do
19
+ sleep 0.1 until locked?
20
+ yield
21
+ end
23
22
  rescue Sidekiq::Shutdown
24
23
  logger.fatal { "the unique_key: #{@unique_digest} needs to be unlocked manually" }
25
24
  raise
26
25
  ensure
27
26
  SidekiqUniqueJobs.connection(@redis_pool) { |conn| conn.del @unique_digest }
28
- MUTEX.unlock
29
27
  end
30
28
 
31
29
  def locked?
@@ -9,7 +9,6 @@ module SidekiqUniqueJobs
9
9
  class UniqueArgs
10
10
  CLASS_NAME = 'SidekiqUniqueJobs::UniqueArgs'
11
11
  extend Forwardable
12
- include Normalizer
13
12
 
14
13
  def_delegators :SidekiqUniqueJobs, :config, :worker_class_constantize
15
14
  def_delegators :Sidekiq, :logger
@@ -62,9 +61,13 @@ module SidekiqUniqueJobs
62
61
  logger.debug { "#{__method__} : unique arguments disabled" }
63
62
  args
64
63
  end
65
- rescue NameError
66
- # fallback to not filtering args when class can't be instantiated
67
- return args
64
+ rescue NameError => ex
65
+ logger.error "#{__method__}(#{args}) : failed with (#{ex.message})"
66
+ logger.error ex
67
+
68
+ raise if config.raise_unique_args_errors
69
+
70
+ args
68
71
  end
69
72
 
70
73
  def unique_on_all_queues?
@@ -114,6 +117,7 @@ module SidekiqUniqueJobs
114
117
  logger.warn { "#{__method__} : unique_args_method is nil. Returning (#{args})" }
115
118
  return args
116
119
  end
120
+
117
121
  filter_args = unique_args_method.call(args)
118
122
  logger.debug { "#{__method__} : #{args} -> #{filter_args}" }
119
123
  filter_args
@@ -1,14 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SidekiqUniqueJobs
4
- module Util
5
- SCAN_PATTERN ||= '*'
6
- DEFAULT_COUNT ||= 1_000
7
- KEYS_METHOD ||= 'keys'
8
- SCAN_METHOD ||= 'scan'
9
- EXPIRE_BATCH_SIZE ||= 100
4
+ module Util # rubocop:disable Metrics/ModuleLength
5
+ COUNT = 'COUNT'
6
+ DEFAULT_COUNT = 1_000
7
+ EXPIRE_BATCH_SIZE = 100
8
+ MATCH = 'MATCH'
9
+ KEYS_METHOD = 'keys'
10
+ SCAN_METHOD = 'scan'
11
+ SCAN_PATTERN = '*'
10
12
 
11
- module_function
13
+ extend self # rubocop:disable Style/ModuleFunction
12
14
 
13
15
  def keys(pattern = SCAN_PATTERN, count = DEFAULT_COUNT)
14
16
  send("keys_by_#{redis_keys_method}", pattern, count)
@@ -26,7 +28,7 @@ module SidekiqUniqueJobs
26
28
  keys, time = timed { keys(pattern, count) }
27
29
  logger.debug { "#{keys.size} matching keys found in #{time} sec." }
28
30
  keys = dry_run(keys)
29
- logger.debug { "#{keys.size} matching keys after postprocessing" }
31
+ logger.debug { "#{keys.size} matching keys after post-processing" }
30
32
  unless dry_run
31
33
  logger.debug { "deleting #{keys}..." }
32
34
  _, time = timed { batch_delete(keys) }
@@ -41,23 +43,33 @@ module SidekiqUniqueJobs
41
43
  end
42
44
  end
43
45
 
44
- def expire
46
+ def expire # rubocop:disable Metrics/MethodLength
45
47
  removed_keys = {}
46
48
  connection do |conn|
47
49
  cursor = '0'
48
- cursor, jobs = conn.hscan(SidekiqUniqueJobs::HASH_KEY, [cursor, 'MATCH', '*', 'COUNT', EXPIRE_BATCH_SIZE])
49
- jobs.each do |job_array|
50
- jid, unique_key = job_array
51
- next if conn.get(unique_key)
52
- conn.hdel(SidekiqUniqueJobs::HASH_KEY, jid)
53
- removed_keys[jid] = unique_key
54
- end
50
+ loop do
51
+ cursor, jobs = get_jobs(conn, cursor)
52
+ jobs.each do |job_array|
53
+ jid, unique_key = job_array
54
+
55
+ next if conn.get(unique_key)
56
+ conn.hdel(SidekiqUniqueJobs::HASH_KEY, jid)
57
+ removed_keys[jid] = unique_key
58
+ end
55
59
 
56
- break if cursor == '0'
60
+ break if cursor == '0'
61
+ end
57
62
  end
63
+
58
64
  removed_keys
59
65
  end
60
66
 
67
+ private
68
+
69
+ def get_jobs(conn, cursor)
70
+ conn.hscan(SidekiqUniqueJobs::HASH_KEY, [cursor, MATCH, SCAN_PATTERN, COUNT, EXPIRE_BATCH_SIZE])
71
+ end
72
+
61
73
  def keys_by_scan(pattern, count)
62
74
  connection { |conn| conn.scan_each(match: prefix(pattern), count: count).to_a }
63
75
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SidekiqUniqueJobs
4
- VERSION = '5.0.9'
4
+ VERSION = '5.0.10'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-unique-jobs
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.9
4
+ version: 5.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikael Henriksson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-06 00:00:00.000000000 Z
11
+ date: 2017-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq