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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43b75e11e1343bf44faec8dec56f4c0356d6bec4549034b2197dd0624eef3fe5
4
- data.tar.gz: 7e6cb6380f3c6544170d699fdd6296726e236761e916921b8a541e025b527e50
3
+ metadata.gz: bc7f82e3d04720a79501ea98300940be276d16484b840fcb29cbde5d9b02d4d0
4
+ data.tar.gz: 2c591c1695107e8afb57dc7ba67451ddcd28518251ce0515ec6fb032ae558975
5
5
  SHA512:
6
- metadata.gz: 02fa7a131157f9aefc859a841571a942c0af8de90accc6fcfc38e9da39e2fa4f88a9cdf1fc0505d9f5869989c29dd5da8299282491c01b1a17302f59212e44ad
7
- data.tar.gz: acca8c9d924c8158f8dba0748808b690106c5f212f2a899e7d4a2286bbf006d9f52880c33d6a89f9463287d172d0e61ccddb057bcfe3e3d18b3e4054554754fd
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.delete_by(digest: msg['unique_digest']) if msg['unique_digest']
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.delete_by(digest: job['unique_digest']) if job['unique_digest']
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
- # Removes the lock keys from Redis
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]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SidekiqUniqueJobs
4
- VERSION = '6.0.1'
4
+ VERSION = '6.0.2'
5
5
  end
@@ -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
- @unique_digests = Digests.all(pattern: @filter, count: @count)
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>
@@ -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
@@ -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
@@ -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, token)
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.1
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-07-31 00:00:00.000000000 Z
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