sidekiq-unique-jobs 2.6.5 → 2.6.6

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: 668f0e7f7a11db5e1ebf8e1d85943911b18c044e
4
- data.tar.gz: 337c9f52503823719953a55a38fcae0f8f17a6d5
3
+ metadata.gz: 2296d65fb90ede4439f99784f379eb23c75d5a1b
4
+ data.tar.gz: 688b666f69e6dbd293e5662047dbe10b0429656a
5
5
  SHA512:
6
- metadata.gz: c0e0c720b227b5eb4b574aaf6064bf27f97e6e79faa253287df3d012bad2248ed098e341379cf9a34f20ba5f744e4f9bdd1dd3dcac79afd995644ce8be185311
7
- data.tar.gz: 5a14117bed073f1e222eb44ee86591ce82dcb4660723bca1a138cfc9f45d9e208b47fafc5d454f29ec23d5756933487a83e6471dd6589590b21bb4241d56135f
6
+ metadata.gz: bea86a75d736637326b092067172db4186dce2689d6811e48227a9e5599c391396df58e17b59f8e34c9de066cae9fafb844195dbe05a4cb23d1f177fbc780458
7
+ data.tar.gz: 29b4d90da37697c917d644f062a6ac05585f6a8952da775eda22ab9bd939aae6e9f4e26196c7cf7011a0c3d848a594f3935ce25e30c54988e4a07f0ebb5cdb63
data/README.md CHANGED
@@ -82,6 +82,6 @@ account for this.
82
82
 
83
83
  ## Contributors
84
84
 
85
- - @sax
86
- - @eduardosasso
87
- - @KensoDev
85
+ - https://github.com/sax
86
+ - https://github.com/eduardosasso
87
+ - https://github.com/KensoDev
@@ -6,8 +6,10 @@ module SidekiqUniqueJobs
6
6
  class UniqueJobs
7
7
  def call(worker_class, item, queue)
8
8
 
9
- enabled = worker_class.get_sidekiq_options['unique'] || item['unique']
10
- unique_job_expiration = worker_class.get_sidekiq_options['unique_job_expiration']
9
+ klass = worker_class_constantize(worker_class)
10
+
11
+ enabled = klass.get_sidekiq_options['unique'] || item['unique']
12
+ unique_job_expiration = klass.get_sidekiq_options['unique_job_expiration']
11
13
 
12
14
  if enabled
13
15
 
@@ -19,14 +21,20 @@ module SidekiqUniqueJobs
19
21
 
20
22
  conn.watch(payload_hash)
21
23
 
22
- if conn.get(payload_hash)
24
+ if conn.get(payload_hash).to_i == 1 ||
25
+ (conn.get(payload_hash).to_i == 2 && item['at'])
26
+ # if the job is already queued, or is already scheduled and
27
+ # we're trying to schedule again, abort
23
28
  conn.unwatch
24
29
  else
30
+ # if the job was previously scheduled and is now being queued,
31
+ # or we've never seen it before
25
32
  expires_at = unique_job_expiration || SidekiqUniqueJobs::Config.default_expiration
26
33
  expires_at = ((Time.at(item['at']) - Time.now.utc) + expires_at).to_i if item['at']
27
34
 
28
35
  unique = conn.multi do
29
- conn.setex(payload_hash, expires_at, 1)
36
+ # set value of 2 for scheduled jobs, 1 for queued jobs.
37
+ conn.setex(payload_hash, expires_at, item['at'] ? 2 : 1)
30
38
  end
31
39
  end
32
40
  end
@@ -36,6 +44,33 @@ module SidekiqUniqueJobs
36
44
  end
37
45
  end
38
46
 
47
+ protected
48
+
49
+ # Attempt to constantize a string worker_class argument, always
50
+ # failing back to the original argument.
51
+ # Duplicates Rails' String.constantize logic for non-Rails cases.
52
+ def worker_class_constantize(worker_class)
53
+ if worker_class.is_a?(String)
54
+ if worker_class.respond_to?(:constantize)
55
+ worker_class.constantize
56
+ else
57
+ # duplicated logic from Rails 3.2.13 ActiveSupport::Inflector
58
+ # https://github.com/rails/rails/blob/9e0b3fc7cfba43af55377488f991348e2de24515/activesupport/lib/active_support/inflector/methods.rb#L213
59
+ names = worker_class.split('::')
60
+ names.shift if names.empty? || names.first.empty?
61
+ constant = Object
62
+ names.each do |name|
63
+ constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
64
+ end
65
+ constant
66
+ end
67
+ else
68
+ worker_class
69
+ end
70
+ rescue
71
+ worker_class
72
+ end
73
+
39
74
  end
40
75
  end
41
76
  end
@@ -1,3 +1,3 @@
1
1
  module SidekiqUniqueJobs
2
- VERSION = "2.6.5"
2
+ VERSION = "2.6.6"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'helper'
2
+ require 'celluloid'
2
3
  require 'sidekiq/worker'
3
4
  require "sidekiq-unique-jobs"
4
5
  require 'sidekiq/scheduled'
@@ -35,6 +36,22 @@ class TestClient < MiniTest::Unit::TestCase
35
36
  assert_equal 1, Sidekiq.redis {|c| c.llen("queue:customqueue") }
36
37
  end
37
38
 
39
+ it 'does not schedule duplicates when calling perform_in' do
40
+ QueueWorker.sidekiq_options :unique => true
41
+ 10.times { QueueWorker.perform_in(60, [1, 2]) }
42
+ assert_equal 1, Sidekiq.redis { |c| c.zcount("schedule", -1, Time.now.to_f + 2 * 60) }
43
+ end
44
+
45
+ it 'enqueues previously scheduled job' do
46
+ QueueWorker.sidekiq_options :unique => true
47
+ QueueWorker.perform_in(60 * 60, 1, 2)
48
+
49
+ # time passes and the job is pulled off the schedule:
50
+ Sidekiq::Client.push('class' => TestClient::QueueWorker, 'queue' => 'customqueue', 'args' => [1, 2])
51
+
52
+ assert_equal 1, Sidekiq.redis {|c| c.llen("queue:customqueue") }
53
+ end
54
+
38
55
  it 'sets an expiration when provided by sidekiq options' do
39
56
  one_hour_expiration = 60 * 60
40
57
  QueueWorker.sidekiq_options :unique => true, :unique_job_expiration => one_hour_expiration
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: 2.6.5
4
+ version: 2.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikael Henriksson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-09 00:00:00.000000000 Z
11
+ date: 2013-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
@@ -153,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
153
  version: '0'
154
154
  requirements: []
155
155
  rubyforge_project:
156
- rubygems_version: 2.0.2
156
+ rubygems_version: 2.0.3
157
157
  signing_key:
158
158
  specification_version: 4
159
159
  summary: The unique jobs that were removed from sidekiq