sidekiq-middleware 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +5 -0
- data/lib/sidekiq-middleware/client/unique_jobs.rb +4 -2
- data/lib/sidekiq-middleware/version.rb +1 -1
- data/sidekiq-middleware.gemspec +2 -1
- data/test/test_unique_jobs.rb +19 -1
- metadata +24 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f04e949a14e7c6eaf7d746573daebbf25ec154f1
|
4
|
+
data.tar.gz: 8de3085809a52b856ad510a9cab0c8d2abb51144
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39b268d9dfbd5c1b95171ff061ac0ed5dc99f803c166baf753b60bc0f58fbaadf07eb76a6a25f6b34cc1532acf04bfea909118edfc286a4efcae92f428319975
|
7
|
+
data.tar.gz: c1b11188de319b8444aa07ce074a9b66a111225bbd7bb00c4cd0b392005e1696417cb95fd17b8cd620c076a1856b8f77a4d5afce5515ff757276cd6a5e2302ce
|
data/CHANGES.md
CHANGED
@@ -12,6 +12,7 @@ module Sidekiq
|
|
12
12
|
|
13
13
|
if enabled
|
14
14
|
unique, payload = false, item.clone.slice(*%w(class queue args at))
|
15
|
+
job_id = item['jid']
|
15
16
|
|
16
17
|
# Enabled unique scheduled
|
17
18
|
if enabled == :all && payload.has_key?('at')
|
@@ -26,11 +27,12 @@ module Sidekiq
|
|
26
27
|
Sidekiq.redis do |conn|
|
27
28
|
conn.watch(payload_hash)
|
28
29
|
|
29
|
-
|
30
|
+
locked_job_id = conn.get(payload_hash)
|
31
|
+
if locked_job_id && locked_job_id != job_id
|
30
32
|
conn.unwatch
|
31
33
|
else
|
32
34
|
unique = conn.multi do
|
33
|
-
conn.setex(payload_hash, expiration,
|
35
|
+
conn.setex(payload_hash, expiration, job_id)
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
data/sidekiq-middleware.gemspec
CHANGED
@@ -14,8 +14,9 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.require_paths = ["lib"]
|
15
15
|
gem.version = Sidekiq::Middleware::VERSION
|
16
16
|
|
17
|
-
gem.add_dependency 'sidekiq', '
|
17
|
+
gem.add_dependency 'sidekiq', '>= 2.12.4', '< 3'
|
18
18
|
gem.add_development_dependency 'rake'
|
19
19
|
gem.add_development_dependency 'bundler', '~> 1.0'
|
20
20
|
gem.add_development_dependency 'minitest', '~> 3'
|
21
|
+
gem.add_development_dependency 'timecop'
|
21
22
|
end
|
data/test/test_unique_jobs.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'securerandom'
|
2
2
|
require 'helper'
|
3
|
+
require 'timecop'
|
3
4
|
require 'sidekiq/client'
|
4
5
|
require 'sidekiq/worker'
|
5
6
|
require 'sidekiq/processor'
|
@@ -8,6 +9,7 @@ require 'sidekiq-middleware'
|
|
8
9
|
class TestUniqueJobs < MiniTest::Unit::TestCase
|
9
10
|
describe 'with real redis' do
|
10
11
|
before do
|
12
|
+
Celluloid.boot
|
11
13
|
@boss = MiniTest::Mock.new
|
12
14
|
@processor = ::Sidekiq::Processor.new(@boss)
|
13
15
|
|
@@ -73,6 +75,19 @@ class TestUniqueJobs < MiniTest::Unit::TestCase
|
|
73
75
|
assert_equal 1, Sidekiq.redis { |c| c.zcard('schedule') }
|
74
76
|
end
|
75
77
|
|
78
|
+
it 'does correctly handle adding to the worker queue when scheduled' do
|
79
|
+
start_time = Time.now - 60
|
80
|
+
queue_time = start_time + 30
|
81
|
+
Timecop.travel start_time do
|
82
|
+
UniqueScheduledWorker.perform_at queue_time, 'x'
|
83
|
+
end
|
84
|
+
assert_equal 1, Sidekiq.redis { |c| c.zcard('schedule') }
|
85
|
+
assert_equal 0, Sidekiq.redis { |c| c.llen('queue:unique_scheduled_queue') }
|
86
|
+
Sidekiq::Scheduled::Poller.new.poll
|
87
|
+
assert_equal 0, Sidekiq.redis { |c| c.zcard('schedule') }
|
88
|
+
assert_equal 1, Sidekiq.redis { |c| c.llen('queue:unique_scheduled_queue') }
|
89
|
+
end
|
90
|
+
|
76
91
|
it 'allows the job to be re-scheduled after processing' do
|
77
92
|
# Schedule
|
78
93
|
5.times { |t| UniqueScheduledWorker.perform_in((t+1)*60, 'args') }
|
@@ -114,7 +129,9 @@ class TestUniqueJobs < MiniTest::Unit::TestCase
|
|
114
129
|
it 'does not duplicate messages with enabled unique option and custom unique lock key' do
|
115
130
|
5.times { CustomUniqueWorker.perform_async('args', false) }
|
116
131
|
assert_equal 1, Sidekiq.redis { |c| c.llen('queue:custom_unique_queue') }
|
117
|
-
|
132
|
+
job = Sidekiq.load_json Sidekiq.redis { |c| c.lpop('queue:custom_unique_queue') }
|
133
|
+
assert job['jid']
|
134
|
+
assert_equal job['jid'], Sidekiq.redis { |c| c.get('custom:unique:lock:args') }
|
118
135
|
end
|
119
136
|
|
120
137
|
it 'does not allow the job to be duplicated when processing job with manual option' do
|
@@ -155,5 +172,6 @@ class TestUniqueJobs < MiniTest::Unit::TestCase
|
|
155
172
|
}
|
156
173
|
assert_equal 5, Sidekiq.redis { |c| c.zcard('schedule') }
|
157
174
|
end
|
175
|
+
|
158
176
|
end
|
159
177
|
end
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-middleware
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Krasnoukhov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 2.12.4
|
20
|
+
- - <
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '3'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- -
|
27
|
+
- - '>='
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: 2.12.4
|
30
|
+
- - <
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: rake
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +72,20 @@ dependencies:
|
|
66
72
|
- - ~>
|
67
73
|
- !ruby/object:Gem::Version
|
68
74
|
version: '3'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: timecop
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
69
89
|
description: Additional sidekiq middleware
|
70
90
|
email:
|
71
91
|
- dmitry@krasnoukhov.com
|