sidekiq-unique-jobs 5.0.8 → 5.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

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: ce50cc9a0255008a8e2fb460ba0c19bc23c835bf
4
- data.tar.gz: 282838bd96a4016fcc9358ea2b003d7d59b4e229
3
+ metadata.gz: 7238f6463cf70d3aa15dfa9f13222bfd095be565
4
+ data.tar.gz: 296c50852200e0fe7f17bef756aa4ed339764c9a
5
5
  SHA512:
6
- metadata.gz: 9aa9bd40afaac4d11d4fa88965b3e2d332ba322e694a950787c11ff7b37059e830350ec49b76e21e1ef9dbac9c3834fb774af29ac4cb1b3165546cd1d551b8fd
7
- data.tar.gz: 7af6f0c5d504eb8883a73be064fdc780690e8f4cdbf85f0b335363461a56af4ec7df405d8c8d28f9a350d848b4d20bff1fceae6e4288a40b07134c2ca4514ad0
6
+ metadata.gz: f3b1d70cb51300b90ed59fc873af2a1722b1775aaea2b077ae9df7b606ebee594bbd8b6ef75611b0ad90ecf7bad7968dd7e05fbbf3c32ffc8bdaac707451f403
7
+ data.tar.gz: a1ab235a39e48aae97df51df2f912b832008ace438903eca2f386221c7c32d02a361af2f8eadf33aa4bd5702db1d6a094e7c522e1a00d864c5c334302b2344af
@@ -1,3 +1,10 @@
1
+ ## v5.0.9
2
+ - [#229](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/#229) Use HSCAN for expiring keys
3
+ - [#232](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/#232) Fix testing helper
4
+
5
+ ## v5.0.8
6
+ - Fixes [#220](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/220)
7
+
1
8
  ## v5.0.7
2
9
  - Fixes [#218](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/218)
3
10
 
data/README.md CHANGED
@@ -161,8 +161,8 @@ class UniqueJobWithFilterMethod
161
161
  sidekiq_options unique: :until_and_while_executing,
162
162
  unique_args: :unique_args
163
163
 
164
- def self.unique_args(name, id, options)
165
- [ name, options[:type] ]
164
+ def self.unique_args(args)
165
+ [ args[0], args[2][:type] ]
166
166
  end
167
167
 
168
168
  ...
data/Rakefile CHANGED
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env rake
2
1
  # frozen_string_literal: true
3
2
 
4
3
  require 'rubygems'
@@ -58,7 +58,7 @@ module SidekiqUniqueJobs
58
58
  # failing back to the original argument.
59
59
  def worker_class_constantize(worker_class)
60
60
  return worker_class unless worker_class.is_a?(String)
61
- worker_class.constantize
61
+ Object.const_get(worker_class)
62
62
  rescue NameError
63
63
  worker_class
64
64
  end
@@ -12,6 +12,22 @@ rescue LoadError
12
12
  end
13
13
  end
14
14
 
15
+ unless {}.respond_to?(:stringify_keys)
16
+ def stringify_keys
17
+ transform_keys(&:to_s)
18
+ end
19
+ end
20
+
21
+ unless {}.respond_to?(:transform_keys)
22
+ def transform_keys
23
+ result = {}
24
+ each_key do |key|
25
+ result[yield(key)] = self[key]
26
+ end
27
+ result
28
+ end
29
+ end
30
+
15
31
  unless {}.respond_to?(:slice!)
16
32
  def slice!(*keys)
17
33
  keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true)
@@ -3,8 +3,7 @@
3
3
  module SidekiqUniqueJobs
4
4
  module OptionsWithFallback
5
5
  def self.included(base)
6
- base.class_attribute :lock_cache unless base.respond_to?(:lock_cache)
7
- base.lock_cache ||= {}
6
+ base.send(:extend, SidekiqUniqueJobs::OptionsWithFallback::ClassMethods)
8
7
  end
9
8
 
10
9
  def unique_enabled?
@@ -24,7 +23,7 @@ module SidekiqUniqueJobs
24
23
  end
25
24
 
26
25
  def lock_class
27
- lock_cache[unique_lock.to_sym] ||= "SidekiqUniqueJobs::Lock::#{unique_lock.to_s.classify}".constantize
26
+ lock_cache[unique_lock.to_sym] ||= Object.const_get("SidekiqUniqueJobs::Lock::#{unique_lock.to_s.classify}")
28
27
  end
29
28
 
30
29
  def unique_lock
@@ -47,11 +46,29 @@ module SidekiqUniqueJobs
47
46
  hash[key]
48
47
  end
49
48
 
49
+ def lock_cache
50
+ self.class.lock_cache
51
+ end
52
+
53
+ def lock_cache=(obj)
54
+ self.class.lock_cache = obj
55
+ end
56
+
50
57
  def options
51
58
  @options ||= worker_class.get_sidekiq_options if worker_class.respond_to?(:get_sidekiq_options)
52
59
  @options ||= Sidekiq.default_worker_options
53
60
  @options ||= {}
54
61
  @options &&= @options.stringify_keys
55
62
  end
63
+
64
+ module ClassMethods
65
+ def lock_cache
66
+ @lock_cache ||= {}
67
+ end
68
+
69
+ def lock_cache=(obj)
70
+ @lock_cache = obj
71
+ end
72
+ end
56
73
  end
57
74
  end
@@ -22,9 +22,10 @@ module SidekiqUniqueJobs
22
22
  stored_jid = conn.get(unique_key)
23
23
 
24
24
  return (stored_jid == job_id) ? 1 : 0 if stored_jid
25
-
26
25
  return 0 unless conn.set(unique_key, job_id, nx: true, ex: expires)
26
+
27
27
  conn.hsetnx(SidekiqUniqueJobs::HASH_KEY, job_id, unique_key)
28
+
28
29
  return 1
29
30
  end
30
31
  end
@@ -40,6 +41,7 @@ module SidekiqUniqueJobs
40
41
 
41
42
  conn.del(unique_key)
42
43
  conn.hdel(SidekiqUniqueJobs::HASH_KEY, job_id)
44
+
43
45
  return 1
44
46
  end
45
47
  end
@@ -46,8 +46,8 @@ module SidekiqUniqueJobs
46
46
  worker_class = SidekiqUniqueJobs.worker_class_constantize(worker_class)
47
47
 
48
48
  if Sidekiq::Testing.inline?
49
- _server.call(worker_class.new, item, queue, redis_pool) do
50
- call_real(worker_class, item, queue, redis_pool) do
49
+ call_real(worker_class, item, queue, redis_pool) do
50
+ _server.call(worker_class.new, item, queue, redis_pool) do
51
51
  yield
52
52
  end
53
53
  end
@@ -6,6 +6,7 @@ module SidekiqUniqueJobs
6
6
  DEFAULT_COUNT ||= 1_000
7
7
  KEYS_METHOD ||= 'keys'
8
8
  SCAN_METHOD ||= 'scan'
9
+ EXPIRE_BATCH_SIZE ||= 100
9
10
 
10
11
  module_function
11
12
 
@@ -43,11 +44,16 @@ module SidekiqUniqueJobs
43
44
  def expire
44
45
  removed_keys = {}
45
46
  connection do |conn|
46
- conn.hgetall(SidekiqUniqueJobs::HASH_KEY).each do |jid, unique_key|
47
+ 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
47
51
  next if conn.get(unique_key)
48
52
  conn.hdel(SidekiqUniqueJobs::HASH_KEY, jid)
49
53
  removed_keys[jid] = unique_key
50
54
  end
55
+
56
+ break if cursor == '0'
51
57
  end
52
58
  removed_keys
53
59
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SidekiqUniqueJobs
4
- VERSION = '5.0.8'
4
+ VERSION = '5.0.9'
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.8
4
+ version: 5.0.9
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-05-03 00:00:00.000000000 Z
11
+ date: 2017-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
@@ -217,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
217
  version: '0'
218
218
  requirements: []
219
219
  rubyforge_project:
220
- rubygems_version: 2.6.11
220
+ rubygems_version: 2.6.12
221
221
  signing_key:
222
222
  specification_version: 4
223
223
  summary: Uniqueness for Sidekiq Jobs