sidekiq-antidote 1.0.0 → 1.1.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: 3692f76b40f4cf3cf7c8231c3a882e09ab5f81dec49cc3711b268602cd9bb0a3
4
- data.tar.gz: 2845af94e4a35930c1cd775a075774ee72a70af2c3a498f802f2cc56f99edf07
3
+ metadata.gz: 9f5bdf47fd299dc626c6fc0afb94896301c66e5b1f9f33875383375d0d5ac483
4
+ data.tar.gz: bb9966c063f7ca0325d31229c6f4d0cf445d53392bb89a201dba92891759ece3
5
5
  SHA512:
6
- metadata.gz: 15c6e2fc733cae175d0e1d3b4b2f23ae666156c0b4386cf51287306d9601e3a09f4fccb2cac5adb6270f7e39e5937b99071e82804666a4fecc130ab2da020c04
7
- data.tar.gz: a7307425321fd20db807a2e16419b6cad463288658cf78ce9063cacf828b83b84977075686882fb35c56e0c87cb8c060dc451bd6a788fe3b8af48f8d892ddc52
6
+ metadata.gz: 87e30e47eb2e37cea51f9037469a4395651d49da8664558d893a71e83d7af275c32ea5ce2e6e8c6b6d464e979af684498972dd2a21c5ddedaf9fe73a2e4a1e62
7
+ data.tar.gz: ffea8f3beef24555534621992e60d18c3c3ec0ab3855e07a65e5a274a434a0285f8442efe851ef8c1377df8f9f72920d290c545b42eb56566c3ee0d53a124362
data/README.adoc CHANGED
@@ -52,6 +52,41 @@ require "sidekiq/web"
52
52
  require "sidekiq/antidote/web"
53
53
  ----
54
54
 
55
+ === Middleware(s)
56
+
57
+ `Sidekiq::Antidote` relies on following bundled middlewares:
58
+
59
+ * `Sidekiq::Antidote::Middlewares::Client`
60
+ * `Sidekiq::Antidote::Middlewares::Server`
61
+
62
+ The middleware is automatically injected when you require `sidekiq/antidote`.
63
+ In rare cases, when this causes an issue, you can change middleware order manually:
64
+
65
+ [source,ruby]
66
+ ----
67
+ Sidekiq.configure_client do |config|
68
+ # ...
69
+
70
+ config.client_middleware do |chain|
71
+ chain.prepend(Sidekiq::Antidote::Middlewares::Client)
72
+ end
73
+ end
74
+
75
+ Sidekiq.configure_server do |config|
76
+ # ...
77
+
78
+ config.client_middleware do |chain|
79
+ chain.prepend(Sidekiq::Antidote::Middlewares::Client)
80
+ end
81
+
82
+ config.server_middleware do |chain|
83
+ chain.prepend(Sidekiq::Antidote::Middlewares::Server)
84
+ end
85
+ end
86
+ ----
87
+
88
+ See: https://github.com/sidekiq/sidekiq/blob/main/lib/sidekiq/middleware/chain.rb
89
+
55
90
 
56
91
  == Inhibitors
57
92
 
@@ -65,10 +100,10 @@ kill::
65
100
  Kill the job (send to the dead set instead of enqueueing and/or performing)
66
101
 
67
102
 
68
- === Antidote Qualifiers
103
+ === Class Qualifiers
69
104
 
70
- Qualifier is the job class pattern. It may match the job class or the job class
71
- and method name (when used with ActionMailer delayed deliveries):
105
+ Class qualifier is the job class pattern. It may match the job class or the job
106
+ class and method name (when used with ActionMailer delayed deliveries):
72
107
 
73
108
  * `ExampleJob`
74
109
  * `Namespaced::ExampleJob`
@@ -90,35 +125,38 @@ You can also use pattern matching:
90
125
  * `{A,B,C}Job` matches `AJob`, `BJob`, and `CJob`
91
126
 
92
127
 
93
- == Supported Ruby Versions
128
+ == Compatibility
94
129
 
95
- This library aims to support and is tested against the following Ruby versions:
130
+ This library aims to support and is tested against:
96
131
 
97
- * Ruby 3.0.x
98
- * Ruby 3.1.x
99
- * Ruby 3.2.x
132
+ * https://www.ruby-lang.org[Ruby]
133
+ ** MRI 3.0.x
134
+ ** MRI 3.1.x
135
+ ** MRI 3.2.x
136
+ ** MRI 3.3.x
137
+ * https://github.com/sidekiq/sidekiq[Sidekiq]
138
+ ** 7.2.x
139
+ ** 7.3.x
140
+ * https://redis.io[Redis]
141
+ ** 6.2.x
142
+ ** 7.0.x
143
+ ** 7.2.x
100
144
 
101
145
  If something doesn't work on one of these versions, it's a bug.
102
146
 
103
- This library may inadvertently work (or seem to work) on other Ruby versions,
104
- however support will only be provided for the versions listed above.
147
+ This library may inadvertently work (or seem to work) on other Ruby, Redis, and
148
+ Sidekiq versions, however support will only be provided for the versions listed
149
+ above.
105
150
 
106
- If you would like this library to support another Ruby version or
107
- implementation, you may volunteer to be a maintainer. Being a maintainer
108
- entails making sure all tests run and pass on that implementation. When
109
- something breaks on your implementation, you will be responsible for providing
110
- patches in a timely fashion. If critical issues for a particular implementation
111
- exist at the time of a major release, support for that Ruby version may be
151
+ If you would like this library to support another Ruby, Redis, or Sidekiq
152
+ version, you may volunteer to be a maintainer. Being a maintainer entails making
153
+ sure all tests run and pass on that implementation. When something breaks on
154
+ your implementation, you will be responsible for providing patches in a timely
155
+ fashion. If critical issues for a particular implementation exist at the time of
156
+ a major release, support for that Ruby, Redis, and/or Sidekiq version may be
112
157
  dropped.
113
158
 
114
159
 
115
- == Supported Sidekiq Versions
116
-
117
- This library aims to support and work with following Sidekiq versions:
118
-
119
- * Sidekiq 7.2.x
120
-
121
-
122
160
  == Development
123
161
 
124
162
  bundle install
@@ -33,10 +33,6 @@ module Sidekiq
33
33
  freeze
34
34
  end
35
35
 
36
- def lethal?
37
- "kill" == treatment
38
- end
39
-
40
36
  def match?(job_record)
41
37
  class_qualifier.match?(job_record.display_class)
42
38
  end
@@ -11,8 +11,8 @@ module Sidekiq
11
11
 
12
12
  # @see https://github.com/sidekiq/sidekiq/wiki/Middleware
13
13
  # @see https://github.com/sidekiq/sidekiq/wiki/Job-Format
14
- def call(_, job_payload, _, _)
15
- yield unless inhibit(job_payload)
14
+ def call(_, job_payload, queue_name, _)
15
+ yield unless inhibit(job_payload, queue_name)
16
16
  end
17
17
  end
18
18
  end
@@ -11,8 +11,8 @@ module Sidekiq
11
11
 
12
12
  # @see https://github.com/sidekiq/sidekiq/wiki/Middleware
13
13
  # @see https://github.com/sidekiq/sidekiq/wiki/Job-Format
14
- def call(_, job_payload, _)
15
- yield unless inhibit(job_payload)
14
+ def call(_, job_payload, queue_name)
15
+ yield unless inhibit(job_payload, queue_name)
16
16
  end
17
17
  end
18
18
  end
@@ -10,17 +10,27 @@ module Sidekiq
10
10
 
11
11
  # @return [true] if message was inhibited
12
12
  # @return [false] otherwise
13
- def inhibit(message)
13
+ def inhibit(message, queue_name)
14
14
  job_record = Sidekiq::JobRecord.new(message)
15
15
  inhibitor = Antidote.remedy_for(job_record)
16
16
  return false unless inhibitor
17
17
 
18
18
  Antidote.log(:warn) { "I've got a poison! -- #{job_record.display_class}" }
19
19
  Antidote.log(:warn) { "I've got a remedy! -- #{inhibitor}" }
20
- DeadSet.new.kill(Sidekiq.dump_json(message)) if inhibitor.lethal?
20
+
21
+ apply_treatment(inhibitor, job_record, queue_name)
21
22
 
22
23
  true
23
24
  end
25
+
26
+ def apply_treatment(inhibitor, job_record, queue_name)
27
+ # Ensure message has queue name
28
+ message = Sidekiq.dump_json(job_record.item.merge({ "queue" => queue_name }))
29
+
30
+ case inhibitor.treatment
31
+ when "kill" then DeadSet.new.kill(message)
32
+ end
33
+ end
24
34
  end
25
35
  end
26
36
  end
@@ -13,9 +13,8 @@ module Sidekiq
13
13
  # @param refresh_rate [Float]
14
14
  # @param repository [Repository]
15
15
  def initialize(refresh_rate, repository:)
16
- @inhibitors = [].freeze
17
- @refresher = Concurrent::TimerTask.new(execution_interval: refresh_rate, run_now: true) do
18
- @inhibitors = repository.to_a.freeze
16
+ @refresher = Concurrent::TimerTask.new(execution_interval: refresh_rate, run_now: true) do
17
+ repository.to_a.freeze
19
18
  end
20
19
  end
21
20
 
@@ -30,7 +29,7 @@ module Sidekiq
30
29
  return to_enum __method__ unless block
31
30
 
32
31
  start_refresher unless refresher_running?
33
- @inhibitors.each(&block)
32
+ @refresher.value&.each(&block)
34
33
 
35
34
  self
36
35
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sidekiq
4
4
  module Antidote
5
- VERSION = "1.0.0"
5
+ VERSION = "1.1.0"
6
6
  end
7
7
  end
data/web/locales/en.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  en:
3
3
  antidote.treatment: Treatment
4
- antidote.qualifier: Qualifier
4
+ antidote.class_qualifier: Class Qualifier
5
5
  antidote.actions: Actions
6
6
  antidote.add: Add Inhibitor
7
7
  antidote.add.submit: Submit
@@ -25,11 +25,11 @@
25
25
  </div>
26
26
  </div>
27
27
  <div class="form-group <%= "has-error" if @class_qualifier_error %>">
28
- <label class="col-sm-2 control-label"><%= t("antidote.qualifier") %></label>
28
+ <label class="col-sm-2 control-label"><%= t("antidote.class_qualifier") %></label>
29
29
  <div class="col-sm-10">
30
- <input id="antidote-inhibitor-qualifier" type="text" class="form-control <%= "is-invalid" if @class_qualifier_error %>" name="class_qualifier" value="<%= @class_qualifier %>">
30
+ <input id="antidote-inhibitor-class-qualifier" type="text" class="form-control <%= "is-invalid" if @class_qualifier_error %>" name="class_qualifier" value="<%= @class_qualifier %>">
31
31
  <% if @class_qualifier_error %>
32
- <div id="antidote-inhibitor-qualifier-error" class="help-block">
32
+ <div id="antidote-inhibitor-class-qualifier-error" class="help-block">
33
33
  <strong>ERROR:</strong> <%= @class_qualifier_error %>
34
34
  </div>
35
35
  <% end %>
@@ -12,7 +12,7 @@
12
12
  <table class="antidote table table-hover table-bordered table-striped">
13
13
  <thead>
14
14
  <th><%= t("antidote.treatment") %></th>
15
- <th><%= t("antidote.qualifier") %></th>
15
+ <th><%= t("antidote.class_qualifier") %></th>
16
16
  <th><%= t("antidote.actions") %></th>
17
17
  </thead>
18
18
  <tbody>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-antidote
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Zapparov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-12-11 00:00:00.000000000 Z
11
+ date: 2024-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -66,9 +66,9 @@ licenses:
66
66
  - MIT
67
67
  metadata:
68
68
  homepage_uri: https://github.com/ixti/sidekiq-antidote
69
- source_code_uri: https://github.com/ixti/sidekiq-antidote/tree/v1.0.0
69
+ source_code_uri: https://github.com/ixti/sidekiq-antidote/tree/v1.1.0
70
70
  bug_tracker_uri: https://github.com/ixti/sidekiq-antidote/issues
71
- changelog_uri: https://github.com/ixti/sidekiq-antidote/blob/v1.0.0/CHANGES.md
71
+ changelog_uri: https://github.com/ixti/sidekiq-antidote/blob/v1.1.0/CHANGES.md
72
72
  rubygems_mfa_required: 'true'
73
73
  post_install_message:
74
74
  rdoc_options: []
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
87
  requirements: []
88
- rubygems_version: 3.4.10
88
+ rubygems_version: 3.5.22
89
89
  signing_key:
90
90
  specification_version: 4
91
91
  summary: Sidekiq poison-pill instant remedy