sidekiq-debouncer 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 939e5397d600c7f5f24b3757f46f0c613369079ef327c8e88bf5adcdf807733f
4
- data.tar.gz: 6ee4f636b9297a232a82bcf6c27c1418408cd2ad66ad8e473945fd1fdbc12cb0
3
+ metadata.gz: bab3413954e727ee13bc4d216f13621d1337df24f1ed970ecf146fae30501ef6
4
+ data.tar.gz: 883a815a2bb23e08abb175bf04f0231e028684d174c3d60bef6cc1450294764d
5
5
  SHA512:
6
- metadata.gz: 3b84978f7ea580d81a052719860ef38fc10339d35064c768457ffcccf0effb7dd148a2bd7a6620489a68c5a03705aea400f2ce8f493e2d0e27fa48edcb806082
7
- data.tar.gz: f0e2d36120e11883f9b2f29b4de2f4fcbfbae075c72592742b9b6a3f323458a0bf7222fb4853604df45c1755e15ead8b600024630bd976631d3df4b5679f996a
6
+ metadata.gz: 254b6d10c2cf611d91e6971f9e21cc76964600ab951f718c88aa0d7eacb38fe3fccc4bd4f0e0f971d33e829e5a6ce0997d5c1a7a9886bc95e503a554b57e0241
7
+ data.tar.gz: 8d5877eec61fb2dbac4305db1815afc320306e0c1af78a872468a5a2218dd48f4b9f8a954e323e59aa3d088b783ae61cc14140a987c3f0785c80a3621c0dcbf7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## Unreleased
2
+
3
+ ## [2.0.2] - 2023-03-13
4
+ - support Sidekiq::Testing
5
+
6
+ ## [2.0.1] - 2023-03-04
7
+ - don't remove debounce key in redis to avoid invalid debouncing
8
+
1
9
  ## [2.0.0] - 2023-02-28
2
10
  Complete rewrite of the library:
3
11
  - Instead of iterating through whole schedule set, sidekiq-debouncer will now cache debounce key in redis with a reference to the job.
data/README.md CHANGED
@@ -88,8 +88,8 @@ Keep in mind that the result of the debounce method will be converted to string,
88
88
 
89
89
  In the application, call `MyWorker.perform_async(...)` as usual. Everytime you call this function, `MyWorker`'s execution will be postponed by 5 minutes. After that time `MyWorker` will receive a method call `perform` with an array of arguments that were provided to the `MyWorker.perform_async(...)` calls.
90
90
 
91
- To avoid keeping leftover keys in redis (for example, when job was manually removed from schedule set), all additional keys are created with TTL.
92
- It's 7 days by default and should be ok in most of the cases. If you are debouncing your jobs in higher interval than that, you can overwrite this setting:
91
+ To avoid keeping leftover keys in redis, all additional keys are created with TTL.
92
+ It's 24 hours by default and should be ok in most of the cases. If you are debouncing your jobs in higher interval than that, you can overwrite this setting:
93
93
 
94
94
  ```ruby
95
95
  Sidekiq.configure_client do |config|
@@ -103,6 +103,15 @@ end
103
103
 
104
104
  In order to test the behavior of `sidekiq-debouncer` it is necessary to disable testing mode. It is the limitation of internal implementation.
105
105
 
106
+ Sidekiq::Debouncer will not debounce the jobs in testing mode, instead they'll be executed like normal jobs (pushed to fake queue or executed inline depending on settings).
107
+ Server middleware needs to be added to `Sidekiq::Testing` chain:
108
+
109
+ ```ruby
110
+ Sidekiq::Testing.server_middleware do |chain|
111
+ chain.add Sidekiq::Debouncer::Middleware::Server
112
+ end
113
+ ```
114
+
106
115
  ## License
107
116
 
108
117
  MIT Licensed. See LICENSE.txt for details.
@@ -17,7 +17,7 @@ module Sidekiq
17
17
  REDIS_ERROR_CLASS = defined?(RedisClient::CommandError) ? RedisClient::CommandError : Redis::CommandError
18
18
 
19
19
  def initialize(options = {})
20
- @debounce_key_ttl = options.fetch(:ttl, 60 * 60 * 24 * 7) # 7 days by default
20
+ @debounce_key_ttl = options.fetch(:ttl, 60 * 60 * 24) # 24 hours by default
21
21
  end
22
22
 
23
23
  def call(worker_class, job, _queue, _redis_pool)
@@ -28,9 +28,6 @@ module Sidekiq
28
28
  return job if !klass.get_sidekiq_options["debounce"] || job["debounce_key"]
29
29
 
30
30
  debounce(klass, job)
31
-
32
- # prevent normal sidekiq flow
33
- false
34
31
  end
35
32
 
36
33
  private
@@ -46,9 +43,14 @@ module Sidekiq
46
43
  job["args"] = [job["args"]]
47
44
  job.delete("debounce")
48
45
 
46
+ return job if testing?
47
+
49
48
  redis do |connection|
50
49
  redis_debounce(connection, keys: ["schedule", key], argv: [Sidekiq.dump_json(job), time, @debounce_key_ttl])
51
50
  end
51
+
52
+ # prevent normal sidekiq flow
53
+ false
52
54
  end
53
55
 
54
56
  def debounce_key(klass, job, options)
@@ -79,6 +81,10 @@ module Sidekiq
79
81
  retry
80
82
  end
81
83
  end
84
+
85
+ def testing?
86
+ defined?(Sidekiq::Testing) && Sidekiq::Testing.enabled?
87
+ end
82
88
  end
83
89
  end
84
90
  end
@@ -3,20 +3,13 @@
3
3
  module Sidekiq
4
4
  module Debouncer
5
5
  module Middleware
6
- # Server middleware removes debounce key from redis before executing the job
6
+ # wrap args into array because sidekiq uses splat while calling perform
7
7
  class Server
8
8
  include Sidekiq::ServerMiddleware
9
9
 
10
10
  def call(_worker, job, _queue)
11
11
  if job.key?("debounce_key")
12
- # skip if job comes from dead or retry set
13
- unless job.key?("failed_at")
14
- redis do |connection|
15
- connection.call("DEL", job["debounce_key"])
16
- end
17
- end
18
-
19
- job["args"] = [job["args"]] # wrap args into array because sidekiq uses splat while calling perform
12
+ job["args"] = [job["args"]]
20
13
  end
21
14
 
22
15
  yield
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sidekiq
4
4
  module Debouncer
5
- VERSION = "2.0.0"
5
+ VERSION = "2.0.2"
6
6
  end
7
7
  end
@@ -12,6 +12,7 @@ Gem::Specification.new do |gem|
12
12
  gem.email = ["sebcioz@gmail.com", "kukicola@gmail.com"]
13
13
  gem.summary = "Sidekiq extension that adds the ability to debounce job execution"
14
14
  gem.description = <<~DESCRIPTION
15
+ Sidekiq extension that adds the ability to debounce job execution.
15
16
  Worker will postpone its execution after `wait time` have elapsed since the last time it was invoked.
16
17
  Useful for implementing behavior that should only happen after the input has stopped arriving.
17
18
  DESCRIPTION
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-debouncer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Zuchmański
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-02-28 00:00:00.000000000 Z
12
+ date: 2023-03-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sidekiq
@@ -102,6 +102,7 @@ dependencies:
102
102
  - !ruby/object:Gem::Version
103
103
  version: 1.24.3
104
104
  description: |
105
+ Sidekiq extension that adds the ability to debounce job execution.
105
106
  Worker will postpone its execution after `wait time` have elapsed since the last time it was invoked.
106
107
  Useful for implementing behavior that should only happen after the input has stopped arriving.
107
108
  email: