unique_job 0.3.2.pre → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +16 -3
- data/lib/unique_job/job_history.rb +9 -2
- data/lib/unique_job/util.rb +9 -7
- data/lib/unique_job/version.rb +1 -1
- data/lib/unique_job.rb +2 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d4face3e0849052a2927072c56bf46be03935a30396a753cd77b1e7eaf7f712
|
4
|
+
data.tar.gz: 8ef8a5cfc6300c524ba994c4a3f1376e3b3f3858618a155bf2919131bed3de3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 144457fd0ad603ed99e494070837c8b2cb30505a0bc0048a48ea9087026de410391a78a0c82a5e3c886777d04e8fa632324a4c4c73690310572108f0fbf4761f
|
7
|
+
data.tar.gz: 9396809dd975fee4a0a7447aa7ba53f1054b07356bda808d6c36344be3e8bf7dc431cb5916d5fdf9df2f7cc668bd464157d583ac2e338df5adcb686254ac3750
|
data/.rspec
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
unique_job (0.3
|
4
|
+
unique_job (0.4.3)
|
5
5
|
redis
|
6
6
|
sidekiq (> 6.0, < 7.0)
|
7
7
|
|
@@ -9,10 +9,23 @@ GEM
|
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
11
|
connection_pool (2.2.3)
|
12
|
-
|
12
|
+
diff-lcs (1.4.4)
|
13
13
|
rack (2.2.3)
|
14
14
|
rake (12.3.3)
|
15
15
|
redis (4.2.2)
|
16
|
+
rspec (3.10.0)
|
17
|
+
rspec-core (~> 3.10.0)
|
18
|
+
rspec-expectations (~> 3.10.0)
|
19
|
+
rspec-mocks (~> 3.10.0)
|
20
|
+
rspec-core (3.10.1)
|
21
|
+
rspec-support (~> 3.10.0)
|
22
|
+
rspec-expectations (3.10.1)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.10.0)
|
25
|
+
rspec-mocks (3.10.2)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.10.0)
|
28
|
+
rspec-support (3.10.3)
|
16
29
|
sidekiq (6.1.2)
|
17
30
|
connection_pool (>= 2.2.2)
|
18
31
|
rack (~> 2.0)
|
@@ -22,8 +35,8 @@ PLATFORMS
|
|
22
35
|
ruby
|
23
36
|
|
24
37
|
DEPENDENCIES
|
25
|
-
minitest (~> 5.0)
|
26
38
|
rake (~> 12.0)
|
39
|
+
rspec
|
27
40
|
unique_job!
|
28
41
|
|
29
42
|
BUNDLED WITH
|
@@ -42,8 +42,15 @@ module UniqueJob
|
|
42
42
|
class << self
|
43
43
|
attr_accessor :redis_options
|
44
44
|
|
45
|
+
MX = Mutex.new
|
46
|
+
|
45
47
|
def redis
|
46
|
-
|
48
|
+
MX.synchronize do
|
49
|
+
unless @redis
|
50
|
+
@redis = Redis.new(redis_options)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
@redis
|
47
54
|
end
|
48
55
|
end
|
49
56
|
|
@@ -60,7 +67,7 @@ module UniqueJob
|
|
60
67
|
super(*args, &blk)
|
61
68
|
rescue => e
|
62
69
|
elapsed = Time.now - start
|
63
|
-
logger.warn "Rescue all errors in #{self.class}##{method_name} #{e.inspect} elapsed=#{sprintf("%.3f sec", elapsed)}"
|
70
|
+
logger.warn "[UniqueJob] Rescue all errors in #{self.class}##{method_name} #{e.inspect} elapsed=#{sprintf("%.3f sec", elapsed)}"
|
64
71
|
logger.debug { e.backtrace.join("\n") }
|
65
72
|
nil
|
66
73
|
end
|
data/lib/unique_job/util.rb
CHANGED
@@ -10,10 +10,7 @@ module UniqueJob
|
|
10
10
|
unique_key = worker.unique_key(*args)
|
11
11
|
logger.debug { "[UniqueJob] Calculate unique key worker=#{worker.class} key=#{unique_key}" }
|
12
12
|
|
13
|
-
if
|
14
|
-
logger.warn { "[UniqueJob] Don't check a job with a blank key worker=#{worker.class} key=#{unique_key}" }
|
15
|
-
yield
|
16
|
-
elsif check_uniqueness(worker, unique_key.to_s)
|
13
|
+
if check_uniqueness(worker, unique_key)
|
17
14
|
yield
|
18
15
|
else
|
19
16
|
logger.debug { "[UniqueJob] Duplicate job skipped worker=#{worker.class} key=#{unique_key}" }
|
@@ -25,13 +22,18 @@ module UniqueJob
|
|
25
22
|
end
|
26
23
|
end
|
27
24
|
|
28
|
-
def check_uniqueness(worker,
|
25
|
+
def check_uniqueness(worker, key)
|
26
|
+
if key.nil? || key.to_s.empty?
|
27
|
+
logger.warn { "[UniqueJob] Don't check a job with a blank key worker=#{worker.class} key=#{key}" }
|
28
|
+
return false
|
29
|
+
end
|
30
|
+
|
29
31
|
history = job_history(worker)
|
30
32
|
|
31
|
-
if history.exists?(
|
33
|
+
if history.exists?(key)
|
32
34
|
false
|
33
35
|
else
|
34
|
-
history.add(
|
36
|
+
history.add(key)
|
35
37
|
true
|
36
38
|
end
|
37
39
|
end
|
data/lib/unique_job/version.rb
CHANGED
data/lib/unique_job.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.3
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ts-3156
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-05 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
|
+
- ".rspec"
|
55
56
|
- ".ruby-version"
|
56
57
|
- ".travis.yml"
|
57
58
|
- CODE_OF_CONDUCT.md
|
@@ -88,9 +89,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
88
89
|
version: 2.3.0
|
89
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
91
|
requirements:
|
91
|
-
- - "
|
92
|
+
- - ">="
|
92
93
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
94
|
+
version: '0'
|
94
95
|
requirements: []
|
95
96
|
rubygems_version: 3.1.6
|
96
97
|
signing_key:
|