sidekiq-rerouting 0.1.0 → 0.2.0

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: 82bc960f510cb4d9d214ee89111b292015a5d9c1f6871e27ed5df98c6733b733
4
- data.tar.gz: 6075abebe883247848cfbba437251fd8fc17c0c0005c2ff85ed4889a8df4f526
3
+ metadata.gz: ebea5ac549b2661e67c1aa3cbc6c387021704376fc169f6578daef26cbf30d64
4
+ data.tar.gz: 42cbc382bac80ac07156d982cc395588da2357914d0a6a256de0b1acf1d128a4
5
5
  SHA512:
6
- metadata.gz: c7a77cbc8402503850d5083207e8f4789a4ad58b03e894c27fa1a5832f34dd3c2e188cdbb4712041aec7a51e994431c80d26eea7d6b210314a8180127d087576
7
- data.tar.gz: d634d71d8616958ac051312145487d48cd8013d48419a9b89b20bbd817564b39c1ffa0a0d525290c12a8df0e3fd85abfcefd833fb9c360398bef649e086caa8c
6
+ metadata.gz: 4be3c9613717b52d8593d5df299b02fca2d2cd195b1870f31965ce513add925b76f44ee5a7fb0e33464bb7a9af24b11a2c58fffd6882f67ccc17dd1560a563c0
7
+ data.tar.gz: 6154bbd5d5055ead93650ebbd5e79f39b929a15d10defba1f9f998895d6881060f755eb527f15af72090d45166381df5f23776734633a90918a8341b2eb3bc2f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.1.0] - 2025-09-19
3
+ ## [0.2.0] - 2025-09-22
4
+
5
+ - **Breaking**: Change configuration of middleware to work with `Sidekiq::Middleware::Chain` API
6
+
7
+ ## [0.1.0] - 2025-09-22
4
8
 
5
9
  - Initial release
data/README.md CHANGED
@@ -6,18 +6,16 @@ A [Sidekiq][sidekiq] extension to set Sidekiq jobs to be rerouted to a different
6
6
 
7
7
  ## Installation
8
8
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
-
11
9
  Install the gem and add to the application's Gemfile by executing:
12
10
 
13
11
  ```bash
14
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
12
+ bundle add sidekiq-rerouting
15
13
  ```
16
14
 
17
15
  If bundler is not being used to manage dependencies, install the gem by executing:
18
16
 
19
17
  ```bash
20
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
18
+ gem install sidekiq-rerouting
21
19
  ```
22
20
 
23
21
  ## Usage
@@ -58,13 +56,57 @@ Clearing all reroutes marks can be done in one fell swoop as well.
58
56
  client.remove_rerouting_for_all
59
57
  ```
60
58
 
59
+ ## Configuration
60
+
61
+ With `sidekiq-rerouting` installed, [register its Sidekiq server middleware][sidekiq-register-middleware].
62
+ Typically this is done via `config/initializers/sidekiq.rb` in a Rails app.
63
+
64
+ ```ruby
65
+ Sidekiq.configure_server do |config|
66
+ config.server_middleware do |chain|
67
+ chain.add Sidekiq::Rerouting::ServerMiddleware
68
+ end
69
+ end
70
+ ```
71
+
72
+ This piece of middleware checks each job, after it's been dequeued, but before its `#perform` has been called, to see if it should be rerouted.
73
+ If the job is marked for rerouting (by job ID or job class), a new job (with the same job ID) is enqueued into the intended destination and the current job exits early.
74
+
75
+ ### Callback
76
+
77
+ If you'd like to do something when a job is rerouted,
78
+ you can optionally pass in an object that responds to `.call` (like a `Proc`) when adding the middleware:
79
+
80
+ ```ruby
81
+ Sidekiq.configure_server do |config|
82
+ config.server_middleware do |chain|
83
+ chain.add(Sidekiq::Rerouting::ServerMiddleware, on_reroute: -> { |job:, old_queue:, new_queue:|
84
+ puts "Job with jid=#{job["jid"]} was rerouted from #{old_queue} to #{new_queue}"
85
+ })
86
+ end
87
+ end
88
+ ```
89
+
90
+ It yields the following keyword arguments:
91
+ * `job`: the serialized job that is being rerouted; see [Sidekiq's docs][job-format] for more details.
92
+ * `old_queue`: the queue *from which* the job is being rerouted.
93
+ * `new_queue`: the queue *to which* the job is being rerouted.
94
+
61
95
  ### Non-Reroutable Jobs
62
96
 
63
97
  By default all Jobs are reroutable.
64
- However, checking if a specific Job should be rerouted is not free; it requires round trip(s) to Redis.
65
- Therefore, you might want to make some Jobs non-reroutable to avoid these extra round trips.
98
+ However, checking if a specific job should be rerouted is not free; it requires round trip(s) to Redis.
99
+ Therefore, you might want to make some jobs non-reroutable to avoid these extra round trips.
66
100
  Or because there are some Jobs that simply should never be rerouted for… _reasons_.
67
101
 
102
+ This is done via a job's `sidekiq_options`.
103
+
104
+ ```ruby
105
+ sidekiq_options reroutable: false
106
+ ```
107
+
108
+ With that in place, the server middleware will ignore the Job, and pass it down the middleware Chain.
109
+ No extra Redis calls, no funny business.
68
110
 
69
111
  ## Development
70
112
 
@@ -84,4 +126,11 @@ The gem is available as open source under the terms of the [MIT License](https:/
84
126
 
85
127
  Everyone interacting in the Sidekiq::Rerouting project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hibachrach/sidekiq-rerouting/blob/main/CODE_OF_CONDUCT.md).
86
128
 
129
+ ## See Also
130
+
131
+ - [`sidekiq-disposal`][sidekiq-disposal]
132
+
87
133
  [sidekiq]: https://sidekiq.org "Simple, efficient background jobs for Ruby."
134
+ [sidekiq-disposal]: https://github.com/hibachrach/sidekiq-disposal "A Sidekiq extension to mark Sidekiq jobs to be disposed of."
135
+ [sidekiq-register-middleware]: https://github.com/sidekiq/sidekiq/wiki/Middleware#registering-middleware "Registering Sidekiq Middleware"
136
+ [job-format]: https://github.com/sidekiq/sidekiq/wiki/Job-Format "How Sidekiq jobs are serialized"
@@ -8,9 +8,9 @@ module Sidekiq
8
8
  class ServerMiddleware
9
9
  include ::Sidekiq::ServerMiddleware
10
10
 
11
- def initialize(client = Client.new, &blk)
12
- @client = client
13
- @on_reroute = blk
11
+ def initialize(opts = {})
12
+ @client = opts.fetch(:client, Client.new)
13
+ @on_reroute = opts.fetch(:on_reroute, nil)
14
14
  end
15
15
 
16
16
  def call(job_instance, job, queue)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sidekiq
4
4
  module Rerouting
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-rerouting
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hazel Bachrach