unique_job 0.2.0 → 0.3.2.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/Gemfile.lock +7 -10
- data/lib/unique_job/client_middleware.rb +4 -0
- data/lib/unique_job/job_history.rb +3 -1
- data/lib/unique_job/server_middleware.rb +4 -0
- data/lib/unique_job/util.rb +10 -9
- data/lib/unique_job/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae29717a10f707ecb27c4ee636e28fc13c7b113ac48cf1837f353c5c2cceee39
|
4
|
+
data.tar.gz: 8a0da599c02f6935a80717afa2e9dcf387722fa768b5b5593323b4041e483402
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e173de697ab852500f66d3fe0dc938ae1d0883ab8cf7b0f0d918043af38490936e3d7917da2ce38deac90f4f68131758eb5d6e001691014465536b2acaacab9
|
7
|
+
data.tar.gz: f17a814a35307b00a4ae7b3347bb7c33690e6db4baa678964fa94db7022505fd6cb5f12d25d7f7c8b8ca3a8ff3f4a3278e2eff400a0ec84e6e1781321dc03be9
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.4
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
unique_job (0.2.
|
4
|
+
unique_job (0.3.2.pre)
|
5
5
|
redis
|
6
6
|
sidekiq (> 6.0, < 7.0)
|
7
7
|
|
@@ -9,17 +9,14 @@ GEM
|
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
11
|
connection_pool (2.2.3)
|
12
|
-
minitest (5.
|
13
|
-
rack (2.2.
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
redis (4.2.1)
|
18
|
-
sidekiq (6.0.7)
|
12
|
+
minitest (5.14.2)
|
13
|
+
rack (2.2.3)
|
14
|
+
rake (12.3.3)
|
15
|
+
redis (4.2.2)
|
16
|
+
sidekiq (6.1.2)
|
19
17
|
connection_pool (>= 2.2.2)
|
20
18
|
rack (~> 2.0)
|
21
|
-
|
22
|
-
redis (>= 4.1.0)
|
19
|
+
redis (>= 4.2.0)
|
23
20
|
|
24
21
|
PLATFORMS
|
25
22
|
ruby
|
data/lib/unique_job/util.rb
CHANGED
@@ -8,26 +8,27 @@ module UniqueJob
|
|
8
8
|
def perform_if_unique(worker, args, &block)
|
9
9
|
if worker.respond_to?(:unique_key)
|
10
10
|
unique_key = worker.unique_key(*args)
|
11
|
+
logger.debug { "[UniqueJob] Calculate unique key worker=#{worker.class} key=#{unique_key}" }
|
11
12
|
|
12
13
|
if unique_key.nil? || unique_key.to_s.empty?
|
13
|
-
logger.warn { "
|
14
|
+
logger.warn { "[UniqueJob] Don't check a job with a blank key worker=#{worker.class} key=#{unique_key}" }
|
14
15
|
yield
|
15
|
-
elsif
|
16
|
+
elsif check_uniqueness(worker, unique_key.to_s)
|
16
17
|
yield
|
18
|
+
else
|
19
|
+
logger.debug { "[UniqueJob] Duplicate job skipped worker=#{worker.class} key=#{unique_key}" }
|
20
|
+
perform_callback(worker, :after_skip, args)
|
21
|
+
nil
|
17
22
|
end
|
18
23
|
else
|
19
24
|
yield
|
20
25
|
end
|
21
26
|
end
|
22
27
|
|
23
|
-
def
|
28
|
+
def check_uniqueness(worker, unique_key)
|
24
29
|
history = job_history(worker)
|
25
30
|
|
26
31
|
if history.exists?(unique_key)
|
27
|
-
logger.info { "#{self.class}##{__method__} Skip duplicate job for #{history.ttl} seconds, remaining #{history.ttl(unique_key)} seconds worker=#{worker.class} args=#{truncate(args.inspect)}" }
|
28
|
-
|
29
|
-
perform_callback(worker, :after_skip, args)
|
30
|
-
|
31
32
|
false
|
32
33
|
else
|
33
34
|
history.add(unique_key)
|
@@ -37,6 +38,7 @@ module UniqueJob
|
|
37
38
|
|
38
39
|
def job_history(worker)
|
39
40
|
ttl = worker.respond_to?(:unique_in) ? worker.unique_in : 3600
|
41
|
+
JobHistory.redis_options = @redis_options
|
40
42
|
JobHistory.new(worker.class, self.class, ttl)
|
41
43
|
end
|
42
44
|
|
@@ -59,8 +61,7 @@ module UniqueJob
|
|
59
61
|
worker.send(callback_name, *args)
|
60
62
|
end
|
61
63
|
rescue ArgumentError => e
|
62
|
-
|
63
|
-
raise ArgumentError.new("#{self.class}:#{worker.class} #{message} callback_name=#{callback_name} args=#{args.inspect} parameters=#{parameters.inspect}")
|
64
|
+
raise ArgumentError.new("[UniqueJob] Invalid parameters callback=#{callback_name}")
|
64
65
|
end
|
65
66
|
end
|
66
67
|
end
|
data/lib/unique_job/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unique_job
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.3.2.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ts-3156
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
@@ -52,6 +52,7 @@ extensions: []
|
|
52
52
|
extra_rdoc_files: []
|
53
53
|
files:
|
54
54
|
- ".gitignore"
|
55
|
+
- ".ruby-version"
|
55
56
|
- ".travis.yml"
|
56
57
|
- CODE_OF_CONDUCT.md
|
57
58
|
- Gemfile
|
@@ -87,12 +88,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
88
|
version: 2.3.0
|
88
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
90
|
requirements:
|
90
|
-
- - "
|
91
|
+
- - ">"
|
91
92
|
- !ruby/object:Gem::Version
|
92
|
-
version:
|
93
|
+
version: 1.3.1
|
93
94
|
requirements: []
|
94
|
-
|
95
|
-
rubygems_version: 2.7.6
|
95
|
+
rubygems_version: 3.1.6
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: Set a uniqueness to Sidekiq jobs
|