sidekiq-unique-jobs 6.0.1 → 6.0.2
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 +4 -4
- data/README.md +2 -2
- data/lib/sidekiq_unique_jobs/digests.rb +17 -0
- data/lib/sidekiq_unique_jobs/locksmith.rb +11 -1
- data/lib/sidekiq_unique_jobs/version.rb +1 -1
- data/lib/sidekiq_unique_jobs/web.rb +4 -2
- data/lib/sidekiq_unique_jobs/web/helpers.rb +14 -0
- data/lib/sidekiq_unique_jobs/web/views/_paging.erb +10 -0
- data/lib/sidekiq_unique_jobs/web/views/unique_digests.erb +1 -1
- data/redis/create.lua +0 -6
- data/redis/expire.lua +14 -0
- data/redis/signal.lua +2 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc7f82e3d04720a79501ea98300940be276d16484b840fcb29cbde5d9b02d4d0
|
4
|
+
data.tar.gz: 2c591c1695107e8afb57dc7ba67451ddcd28518251ce0515ec6fb032ae558975
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b27618d4859b77a8960bc8779e9d62a39c856b58fc6d3cabf3b6650c2021f1288b41224a81fe4c5339a42fb7e20ec02b64f4455fdf2b3e250529aec436b4c51
|
7
|
+
data.tar.gz: 0aab133cbd5ae5ca3b16af1c5995a32cd455e2eef50ab896bbeaf494da6b222f7c198fca0ba1f2e523c449fcad5515d5ee98b63919d9600d6c6465e0b30084a4
|
data/README.md
CHANGED
@@ -361,7 +361,7 @@ For sidekiq versions before 5.1 a `sidekiq_retries_exhausted` block is required
|
|
361
361
|
```ruby
|
362
362
|
class MyWorker
|
363
363
|
sidekiq_retries_exhausted do |msg, _ex|
|
364
|
-
SidekiqUniqueJobs::Digests.
|
364
|
+
SidekiqUniqueJobs::Digests.del(digest: msg['unique_digest']) if msg['unique_digest']
|
365
365
|
end
|
366
366
|
end
|
367
367
|
```
|
@@ -372,7 +372,7 @@ Starting in v5.1, Sidekiq can also fire a global callback when a job dies:
|
|
372
372
|
# this goes in your initializer
|
373
373
|
Sidekiq.configure_server do |config|
|
374
374
|
config.death_handlers << ->(job, _ex) do
|
375
|
-
SidekiqUniqueJobs::Digests.
|
375
|
+
SidekiqUniqueJobs::Digests.del(digest: job['unique_digest']) if job['unique_digest']
|
376
376
|
end
|
377
377
|
end
|
378
378
|
```
|
@@ -22,6 +22,23 @@ module SidekiqUniqueJobs
|
|
22
22
|
redis { |conn| conn.sscan_each(UNIQUE_SET, match: pattern, count: count).to_a }
|
23
23
|
end
|
24
24
|
|
25
|
+
# Paginate unique digests
|
26
|
+
#
|
27
|
+
# @param [String] pattern a pattern to match with
|
28
|
+
# @param [Integer] page the current cursor position
|
29
|
+
# @param [Integer] count the maximum number to match
|
30
|
+
# @return [Array<String>] with unique digests
|
31
|
+
def page(pattern: SCAN_PATTERN, cursor: 0, page_size: 100)
|
32
|
+
redis do |conn|
|
33
|
+
total_size, digests = conn.multi do
|
34
|
+
conn.scard(UNIQUE_SET)
|
35
|
+
conn.sscan(UNIQUE_SET, cursor, match: pattern, count: page_size)
|
36
|
+
end
|
37
|
+
|
38
|
+
[total_size, digests[0], digests[1]]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
25
42
|
# Get a total count of unique digests
|
26
43
|
#
|
27
44
|
# @return [Integer] number of digests
|
@@ -32,6 +32,16 @@ module SidekiqUniqueJobs
|
|
32
32
|
keys: [exists_key, grabbed_key, available_key, version_key, UNIQUE_SET, unique_digest],
|
33
33
|
argv: [jid, expiration, API_VERSION, concurrency],
|
34
34
|
)
|
35
|
+
expire
|
36
|
+
end
|
37
|
+
|
38
|
+
def expire
|
39
|
+
Scripts.call(
|
40
|
+
:expire,
|
41
|
+
redis_pool,
|
42
|
+
keys: [exists_key, available_key, version_key],
|
43
|
+
argv: [expiration],
|
44
|
+
)
|
35
45
|
end
|
36
46
|
|
37
47
|
# Checks if the exists key is created in redis
|
@@ -86,7 +96,7 @@ module SidekiqUniqueJobs
|
|
86
96
|
signal(jid)
|
87
97
|
end
|
88
98
|
|
89
|
-
#
|
99
|
+
# Checks if this instance is considered locked
|
90
100
|
# @param [String] token the unique token to check for a lock.
|
91
101
|
# nil will default to the jid provided in the initializer
|
92
102
|
# @return [true, false]
|
@@ -20,11 +20,13 @@ module SidekiqUniqueJobs
|
|
20
20
|
end
|
21
21
|
|
22
22
|
app.get '/unique_digests' do
|
23
|
-
@total_size = Digests.count
|
24
23
|
@filter = params[:filter] || '*'
|
25
24
|
@filter = '*' if @filter == ''
|
26
25
|
@count = (params[:count] || 100).to_i
|
27
|
-
@
|
26
|
+
@current_cursor = params[:cursor]
|
27
|
+
@prev_cursor = params[:prev_cursor]
|
28
|
+
@total_size, @next_cursor, @unique_digests =
|
29
|
+
Digests.page(pattern: @filter, cursor: @current_cursor, page_size: @count)
|
28
30
|
|
29
31
|
erb(unique_template(:unique_digests))
|
30
32
|
end
|
@@ -9,6 +9,20 @@ module SidekiqUniqueJobs
|
|
9
9
|
File.open(File.join(VIEW_PATH, "#{name}.erb")).read
|
10
10
|
end
|
11
11
|
|
12
|
+
SAFE_CPARAMS = %w[cursor prev_cursor].freeze
|
13
|
+
|
14
|
+
def cparams(options)
|
15
|
+
# stringify
|
16
|
+
options.keys.each do |key|
|
17
|
+
options[key.to_s] = options.delete(key)
|
18
|
+
end
|
19
|
+
|
20
|
+
params.merge(options).map do |key, value|
|
21
|
+
next unless SAFE_CPARAMS.include?(key)
|
22
|
+
"#{key}=#{CGI.escape(value.to_s)}"
|
23
|
+
end.compact.join('&')
|
24
|
+
end
|
25
|
+
|
12
26
|
def redirect_to(subpath)
|
13
27
|
if respond_to?(:to)
|
14
28
|
# Sinatra-based web UI
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<ul class="pagination pull-right flip">
|
2
|
+
<% if @prev_cursor %>
|
3
|
+
<li>
|
4
|
+
<a href="<%= url %>?<%= cparams(cursor: @prev_cursor, prev_cursor: @next_cursor) %>">Previous <%= @count %></a>
|
5
|
+
</li>
|
6
|
+
<% end %>
|
7
|
+
<li>
|
8
|
+
<a href="<%= url %>?<%= cparams(cursor: @next_cursor, prev_cursor: @current_cursor) %>">Next <%= @count %></a>
|
9
|
+
</li>
|
10
|
+
</ul>
|
@@ -9,7 +9,7 @@
|
|
9
9
|
</form>
|
10
10
|
<% if @unique_digests.size > 0 && @total_size > @count.to_i %>
|
11
11
|
<div class="col-sm-4">
|
12
|
-
<%= erb :_paging, locals: { url: "#{root_path}unique_digests" } %>
|
12
|
+
<%= erb unique_template(:_paging), locals: { url: "#{root_path}unique_digests" } %>
|
13
13
|
</div>
|
14
14
|
<% end %>
|
15
15
|
</header>
|
data/redis/create.lua
CHANGED
@@ -45,10 +45,4 @@ end
|
|
45
45
|
redis.call('GETSET', version_key, api_version)
|
46
46
|
redis.call('PERSIST', exists_key)
|
47
47
|
|
48
|
-
if expiration then
|
49
|
-
redis.call('EXPIRE', available_key, expiration)
|
50
|
-
redis.call('EXPIRE', exists_key, expiration)
|
51
|
-
redis.call('EXPIRE', version_key, expiration)
|
52
|
-
end
|
53
|
-
|
54
48
|
return job_id
|
data/redis/expire.lua
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
-- redis.replicate_commands();
|
2
|
+
|
3
|
+
local exists_key = KEYS[1]
|
4
|
+
local available_key = KEYS[2]
|
5
|
+
local version_key = KEYS[3]
|
6
|
+
|
7
|
+
local expiration = tonumber(ARGV[1])
|
8
|
+
|
9
|
+
if expiration then
|
10
|
+
redis.log(redis.LOG_DEBUG, "create.lua - expiring locks because expiration: " .. tostring(expiration))
|
11
|
+
redis.call('EXPIRE', available_key, expiration)
|
12
|
+
redis.call('EXPIRE', exists_key, expiration)
|
13
|
+
redis.call('EXPIRE', version_key, expiration)
|
14
|
+
end
|
data/redis/signal.lua
CHANGED
@@ -9,7 +9,7 @@ local token = ARGV[1]
|
|
9
9
|
local expiration = tonumber(ARGV[2])
|
10
10
|
|
11
11
|
redis.call('HDEL', grabbed_key, token)
|
12
|
-
redis.call('SREM', unique_keys,
|
12
|
+
redis.call('SREM', unique_keys, unique_digest)
|
13
13
|
local available_count = redis.call('LPUSH', available_key, token)
|
14
14
|
|
15
15
|
if expiration then
|
@@ -21,3 +21,4 @@ if expiration then
|
|
21
21
|
end
|
22
22
|
|
23
23
|
return available_count
|
24
|
+
|
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: 6.0.
|
4
|
+
version: 6.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikael Henriksson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -306,6 +306,7 @@ files:
|
|
306
306
|
- lib/sidekiq_unique_jobs/version.rb
|
307
307
|
- lib/sidekiq_unique_jobs/web.rb
|
308
308
|
- lib/sidekiq_unique_jobs/web/helpers.rb
|
309
|
+
- lib/sidekiq_unique_jobs/web/views/_paging.erb
|
309
310
|
- lib/sidekiq_unique_jobs/web/views/unique_digest.erb
|
310
311
|
- lib/sidekiq_unique_jobs/web/views/unique_digests.erb
|
311
312
|
- redis/acquire_lock.lua
|
@@ -313,6 +314,7 @@ files:
|
|
313
314
|
- redis/delete.lua
|
314
315
|
- redis/delete_by_digest.lua
|
315
316
|
- redis/delete_job_by_digest.lua
|
317
|
+
- redis/expire.lua
|
316
318
|
- redis/release_lock.lua
|
317
319
|
- redis/release_stale_locks.lua
|
318
320
|
- redis/signal.lua
|