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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c480f4b0fe78931cf109fbca3db98032cd5bc2e1ad065dc218c56e1ac00361b5
4
- data.tar.gz: e67b02dd3bde8bfb46d417e46bac20780f7c05eb67dcd44f93d9fda831ecde15
3
+ metadata.gz: ae29717a10f707ecb27c4ee636e28fc13c7b113ac48cf1837f353c5c2cceee39
4
+ data.tar.gz: 8a0da599c02f6935a80717afa2e9dcf387722fa768b5b5593323b4041e483402
5
5
  SHA512:
6
- metadata.gz: 44785d034535d444ee219a7b0ad0dd064b02b85aee5289f13ba74a1c2d4fded15898ed2b974c4be4fbc5d6644bf4ba4e704a461c2f3f96b8341e93ea9aeb6dbc
7
- data.tar.gz: bd9b4b1ef9d56ae58f724d1dc827f3747895154b0f7fd978dfd1739e02fdb547fb1d3ee1d2ea5d667e92b572ad1bc1448e579fcd181b7da53acd1c811ab16f55
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.0)
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.11.3)
13
- rack (2.2.2)
14
- rack-protection (2.0.8.1)
15
- rack
16
- rake (12.3.2)
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
- rack-protection (>= 2.0.0)
22
- redis (>= 4.1.0)
19
+ redis (>= 4.2.0)
23
20
 
24
21
  PLATFORMS
25
22
  ruby
@@ -4,6 +4,10 @@ module UniqueJob
4
4
  class ClientMiddleware
5
5
  include Util
6
6
 
7
+ def initialize(redis_options)
8
+ @redis_options = redis_options
9
+ end
10
+
7
11
  def call(worker_str, job, queue, redis_pool, &block)
8
12
  if job.has_key?('at')
9
13
  # perform_in or perform_at
@@ -40,8 +40,10 @@ module UniqueJob
40
40
  end
41
41
 
42
42
  class << self
43
+ attr_accessor :redis_options
44
+
43
45
  def redis
44
- @redis ||= Redis.client(ENV['REDIS_HOST'])
46
+ @redis ||= Redis.new(redis_options)
45
47
  end
46
48
  end
47
49
 
@@ -4,6 +4,10 @@ module UniqueJob
4
4
  class ServerMiddleware
5
5
  include Util
6
6
 
7
+ def initialize(redis_options)
8
+ @redis_options = redis_options
9
+ end
10
+
7
11
  def call(worker, msg, queue, &block)
8
12
  perform_if_unique(worker, msg['args'], &block)
9
13
  end
@@ -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 { "#{self.class}##{__method__} Key is blank worker=#{worker.class} args=#{truncate(args.inspect)}" }
14
+ logger.warn { "[UniqueJob] Don't check a job with a blank key worker=#{worker.class} key=#{unique_key}" }
14
15
  yield
15
- elsif perform_unique_check(worker, args, unique_key.to_s)
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 perform_unique_check(worker, args, unique_key)
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
- message = "The number of parameters of the callback method (#{parameters.size}) is not the same as the number of arguments (#{args.size})"
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
@@ -1,3 +1,3 @@
1
1
  module UniqueJob
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.2.pre"
3
3
  end
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.0
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: 2020-08-17 00:00:00.000000000 Z
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: '0'
93
+ version: 1.3.1
93
94
  requirements: []
94
- rubyforge_project:
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