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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f349d0be192e15acd3e7583662a4011e858b80f1
4
- data.tar.gz: 70041e4a2eb69940fa1ae24fa89339d06d13b733
3
+ metadata.gz: f04e949a14e7c6eaf7d746573daebbf25ec154f1
4
+ data.tar.gz: 8de3085809a52b856ad510a9cab0c8d2abb51144
5
5
  SHA512:
6
- metadata.gz: 77faf9f4982d9cd4c7334ed3368e356192fec79e893c82e643a4597230ebf91dbc7f028321d0d7c3a6120e8cd317b2c8808431d277a89c63ab6c6ea454ef386a
7
- data.tar.gz: f660c82eaddfad7ba5b6ecaedc94700e63cfcd4a0d784a4a37bce265c3ebfbdafa62b8b55e6a58a64d20f68837830459ec7e7c2a72d94db365b8134efbbec140
6
+ metadata.gz: 39b268d9dfbd5c1b95171ff061ac0ed5dc99f803c166baf753b60bc0f58fbaadf07eb76a6a25f6b34cc1532acf04bfea909118edfc286a4efcae92f428319975
7
+ data.tar.gz: c1b11188de319b8444aa07ce074a9b66a111225bbd7bb00c4cd0b392005e1696417cb95fd17b8cd620c076a1856b8f77a4d5afce5515ff757276cd6a5e2302ce
data/CHANGES.md CHANGED
@@ -1,3 +1,8 @@
1
+ 0.1.4
2
+ -----------
3
+
4
+ - Make sure that scheduled unique jobs correctly move from the queue to work ([Sutto](https://github.com/Sutto))
5
+
1
6
  0.1.3
2
7
  -----------
3
8
 
@@ -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
- if conn.get(payload_hash)
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, 1)
35
+ conn.setex(payload_hash, expiration, job_id)
34
36
  end
35
37
  end
36
38
  end
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Middleware
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
@@ -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', '~> 2.12.4'
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
@@ -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
- assert_equal 1, Sidekiq.redis { |c| c.get('custom:unique:lock:args').to_i }
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.3
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-06-22 00:00:00.000000000 Z
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