sidekiq-middleware 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +6 -1
- data/lib/sidekiq-middleware.rb +1 -1
- data/lib/sidekiq-middleware/client/unique_jobs.rb +3 -3
- data/lib/sidekiq-middleware/{worker.rb → helpers.rb} +12 -14
- data/lib/sidekiq-middleware/server/unique_jobs.rb +3 -3
- data/lib/sidekiq-middleware/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 609eb41397719043e799e6d311934fd35d16e858
|
4
|
+
data.tar.gz: 9cda80867210d8a012225fb75481354d6f2242b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 203ae14906166bbf98c759bb9d6b6ae2308c152009ffefd470d81f69dff88809ff97d5666ea29cc1b7e80155d6e7e5acf6bd4316f69d4e9a881bb47ca6b07e59
|
7
|
+
data.tar.gz: b9c90463c8f03574784263b41daf28b2d18ba8d3aca3b24364fb6a918890327bf98b5f40b130939e4f8a53f51767fb1a9c059dc7c8a6ec1f2f44e893faee1dc4
|
data/CHANGES.md
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
+
0.2.1
|
2
|
+
-----------
|
3
|
+
|
4
|
+
- Make middleware work properly even for ```Sidekiq::Extensions``` workers ([dimko](https://github.com/dimko))
|
5
|
+
|
1
6
|
0.2.0
|
2
7
|
-----------
|
3
8
|
|
4
|
-
- Fix scheduled jobs locking when ```unique``` is not set to ```:all``` ([dimko](https://github.com/dimko))
|
9
|
+
- Fix redundant scheduled jobs locking when ```unique``` is not set to ```:all``` ([dimko](https://github.com/dimko))
|
5
10
|
|
6
11
|
0.1.4
|
7
12
|
-----------
|
data/lib/sidekiq-middleware.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'digest/md5'
|
2
2
|
require 'sidekiq-middleware/version'
|
3
3
|
require 'sidekiq-middleware/core_ext'
|
4
|
-
require 'sidekiq-middleware/
|
4
|
+
require 'sidekiq-middleware/helpers'
|
5
5
|
require 'sidekiq-middleware/server/unique_jobs'
|
6
6
|
require 'sidekiq-middleware/client/unique_jobs'
|
7
7
|
require 'sidekiq-middleware/middleware'
|
@@ -4,10 +4,10 @@ module Sidekiq
|
|
4
4
|
class UniqueJobs
|
5
5
|
def call(worker_class, item, queue)
|
6
6
|
worker_class = worker_class.constantize if worker_class.is_a?(String)
|
7
|
-
enabled =
|
7
|
+
enabled = Sidekiq::Middleware::Helpers.unique_enabled?(worker_class, item)
|
8
8
|
|
9
9
|
if enabled
|
10
|
-
expiration =
|
10
|
+
expiration = Sidekiq::Middleware::Helpers.unique_exiration(worker_class)
|
11
11
|
job_id = item['jid']
|
12
12
|
unique = false
|
13
13
|
|
@@ -18,7 +18,7 @@ module Sidekiq
|
|
18
18
|
expiration += (item['at'].to_i - Time.now.to_i)
|
19
19
|
end
|
20
20
|
|
21
|
-
unique_key =
|
21
|
+
unique_key = Sidekiq::Middleware::Helpers.unique_digest(worker_class, item)
|
22
22
|
|
23
23
|
Sidekiq.redis do |conn|
|
24
24
|
conn.watch(unique_key)
|
@@ -1,12 +1,14 @@
|
|
1
1
|
module Sidekiq
|
2
2
|
module Middleware
|
3
|
-
module
|
3
|
+
module Helpers
|
4
|
+
extend self
|
5
|
+
|
4
6
|
UNIQUE_EXPIRATION = 30 * 60 # 30 minutes
|
5
7
|
|
6
|
-
def unique_digest(item)
|
7
|
-
if respond_to?(:lock)
|
8
|
+
def unique_digest(klass, item)
|
9
|
+
if klass.respond_to?(:lock)
|
8
10
|
args = item['args']
|
9
|
-
lock(*args)
|
11
|
+
klass.lock(*args)
|
10
12
|
else
|
11
13
|
dumped = Sidekiq.dump_json(item.slice('class', 'queue', 'args'))
|
12
14
|
digest = Digest::MD5.hexdigest(dumped)
|
@@ -15,25 +17,21 @@ module Sidekiq
|
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
18
|
-
def unique_exiration
|
19
|
-
get_sidekiq_options['expiration'] || UNIQUE_EXPIRATION
|
20
|
+
def unique_exiration(klass)
|
21
|
+
klass.get_sidekiq_options['expiration'] || UNIQUE_EXPIRATION
|
20
22
|
end
|
21
23
|
|
22
|
-
def unique_enabled?(item)
|
23
|
-
enabled = get_sidekiq_options['unique']
|
24
|
+
def unique_enabled?(klass, item)
|
25
|
+
enabled = klass.get_sidekiq_options['unique']
|
24
26
|
if item.has_key?('at') && enabled != :all
|
25
27
|
enabled = false
|
26
28
|
end
|
27
29
|
enabled
|
28
30
|
end
|
29
31
|
|
30
|
-
def unique_manual?
|
31
|
-
get_sidekiq_options['manual']
|
32
|
+
def unique_manual?(klass)
|
33
|
+
klass.get_sidekiq_options['manual']
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
36
|
-
|
37
|
-
Sidekiq::Worker::ClassMethods.class_eval do
|
38
|
-
include Sidekiq::Middleware::Worker
|
39
|
-
end
|
@@ -4,13 +4,13 @@ module Sidekiq
|
|
4
4
|
class UniqueJobs
|
5
5
|
def call(worker_instance, item, queue)
|
6
6
|
worker_class = worker_instance.class
|
7
|
-
enabled =
|
7
|
+
enabled = Sidekiq::Middleware::Helpers.unique_enabled?(worker_class, item)
|
8
8
|
|
9
9
|
if enabled
|
10
10
|
begin
|
11
11
|
yield
|
12
12
|
ensure
|
13
|
-
unless
|
13
|
+
unless Sidekiq::Middleware::Helpers.unique_manual?(worker_class)
|
14
14
|
clear(worker_class, item)
|
15
15
|
end
|
16
16
|
end
|
@@ -21,7 +21,7 @@ module Sidekiq
|
|
21
21
|
|
22
22
|
def clear(worker_class, item)
|
23
23
|
Sidekiq.redis do |conn|
|
24
|
-
conn.del
|
24
|
+
conn.del Sidekiq::Middleware::Helpers.unique_digest(worker_class, item)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-middleware
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Krasnoukhov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
@@ -103,10 +103,10 @@ files:
|
|
103
103
|
- lib/sidekiq-middleware.rb
|
104
104
|
- lib/sidekiq-middleware/client/unique_jobs.rb
|
105
105
|
- lib/sidekiq-middleware/core_ext.rb
|
106
|
+
- lib/sidekiq-middleware/helpers.rb
|
106
107
|
- lib/sidekiq-middleware/middleware.rb
|
107
108
|
- lib/sidekiq-middleware/server/unique_jobs.rb
|
108
109
|
- lib/sidekiq-middleware/version.rb
|
109
|
-
- lib/sidekiq-middleware/worker.rb
|
110
110
|
- sidekiq-middleware.gemspec
|
111
111
|
- test/helper.rb
|
112
112
|
- test/test_core_ext.rb
|