sidekiq-rescue 0.2.0 → 0.2.1
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 +4 -4
- data/CHANGELOG.md +7 -1
- data/README.md +63 -1
- data/lib/sidekiq/rescue/rspec/matchers.rb +50 -0
- data/lib/sidekiq/rescue/version.rb +1 -1
- data/lib/sidekiq_rescue.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1a8899e388b21924f60017c1eb3b724bc129bec25c96f4765a37ab1f1d8e7fb
|
4
|
+
data.tar.gz: 41c934da18716cf917af164e92ce1bccdcab1a5bbce08df1c4cbf6550d5cfe70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a644feb9b9c4d3e1eef97d24738b1157c7efc370102d3db19db3df23f2133382878a264818b5a9a99059e1f64e9b60cbe8e4ea8b297757a760e00fb1df71865b
|
7
|
+
data.tar.gz: 678d83f42a1ffff8dd71def36911fcdc42b7cf2186e053e47b02c9d4237ea51efc2bd10ed003c7909ec830006b3e725b5e64253faca3c0d4555d97a8536be114
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.2.1] - 2024-02-27
|
4
|
+
|
5
|
+
- Fix readme with correct middleware name
|
6
|
+
- Add RSpec matchers
|
7
|
+
|
3
8
|
## [0.2.0] - 2024-02-03
|
4
9
|
|
5
10
|
- Rename `Sidekiq::Rescue::DSL` to `Sidekiq::Rescue::Dsl`
|
@@ -15,6 +20,7 @@
|
|
15
20
|
- Add documentation
|
16
21
|
- Add CI
|
17
22
|
|
18
|
-
[Unreleased]: https://github.com/moofkit/sidekiq-rescue/compare/v0.2.
|
23
|
+
[Unreleased]: https://github.com/moofkit/sidekiq-rescue/compare/v0.2.1...HEAD
|
24
|
+
[0.2.1]: https://github.com/moofkit/sidekiq-rescue/releases/tag/v0.2.1
|
19
25
|
[0.2.0]: https://github.com/moofkit/sidekiq-rescue/releases/tag/v0.2.0
|
20
26
|
[0.1.0]: https://github.com/moofkit/sidekiq-rescue/releases/tag/v0.1.0
|
data/README.md
CHANGED
@@ -27,7 +27,7 @@ Or install it yourself as:
|
|
27
27
|
```ruby
|
28
28
|
Sidekiq.configure_server do |config|
|
29
29
|
config.server_middleware do |chain|
|
30
|
-
chain.add Sidekiq::Rescue::
|
30
|
+
chain.add Sidekiq::Rescue::ServerMiddleware
|
31
31
|
end
|
32
32
|
end
|
33
33
|
```
|
@@ -93,6 +93,68 @@ Sidekiq::Rescue.configure do |config|
|
|
93
93
|
end
|
94
94
|
```
|
95
95
|
|
96
|
+
### Testing
|
97
|
+
|
98
|
+
1. Unit tests (recommended)
|
99
|
+
|
100
|
+
In case you want to test the rescue configuration, this gem provides RSpec matchers:
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
RSpec.cofigure do |config|
|
104
|
+
config.include Sidekiq::Rescue::RSpec::Matchers, type: :job
|
105
|
+
end
|
106
|
+
|
107
|
+
RSpec.describe MyJob do
|
108
|
+
it "rescues from expected errors" do
|
109
|
+
expect(MyJob).to have_sidekiq_rescue(ExpectedError)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
```
|
113
|
+
|
114
|
+
It also provides a way to test the delay and limit:
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
RSpec.describe MyJob do
|
118
|
+
it "rescues from expected errors with custom delay and limit" do
|
119
|
+
expect(MyJob).to have_sidekiq_rescue(ExpectedError).with_delay(60).with_limit(5)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
```
|
123
|
+
|
124
|
+
2. Integration tests with `Sidekiq::Testing`
|
125
|
+
Firstly, you need to configure `Sidekiq::Testing` to use `Sidekiq::Rescue::ServerMiddleware` middleware:
|
126
|
+
|
127
|
+
```ruby
|
128
|
+
# spec/spec_helper.rb or spec/rails_helper.rb
|
129
|
+
require "sidekiq/testing"
|
130
|
+
|
131
|
+
RSpec.configure do |config|
|
132
|
+
config.before(:all) do
|
133
|
+
Sidekiq::Testing.fake!
|
134
|
+
|
135
|
+
Sidekiq::Testing.server_middleware do |chain|
|
136
|
+
chain.add Sidekiq::Rescue::ServerMiddleware
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
```
|
141
|
+
|
142
|
+
And test the job with the next snippet
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
# spec/jobs/my_job_spec.rb
|
146
|
+
RSpec.describe MyJob do
|
147
|
+
before do
|
148
|
+
allow(ApiClient).to receive(:new).and_raise(ApiClient::SomethingWentWrongError)
|
149
|
+
end
|
150
|
+
|
151
|
+
it "retries job if it fails with ExpectedError" do
|
152
|
+
MyJob.perform_async('test')
|
153
|
+
expect { MyJob.perform_one }.not_to raise_error # pefrom_one is a method from Sidekiq::Testing that runs the job once
|
154
|
+
end
|
155
|
+
end
|
156
|
+
```
|
157
|
+
|
96
158
|
## Use cases
|
97
159
|
|
98
160
|
Sidekiq::Rescue is useful when you want to retry jobs that failed due to expected errors and not spam your exception tracker with these errors. For example, you may want to retry a job that failed due to a network error or a temporary outage of a third party service, rather than a bug in your code.
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
return unless defined?(RSpec)
|
4
|
+
|
5
|
+
require "rspec/matchers"
|
6
|
+
|
7
|
+
module Sidekiq
|
8
|
+
module Rescue
|
9
|
+
module RSpec
|
10
|
+
# RSpec matchers for Sidekiq::Rescue
|
11
|
+
module Matchers
|
12
|
+
::RSpec::Matchers.define :have_sidekiq_rescue do |expected| # rubocop:disable Metrics/BlockLength
|
13
|
+
description { "be rescueable with #{expected}" }
|
14
|
+
failure_message do |actual|
|
15
|
+
str = "expected #{actual} to be rescueable with #{expected}"
|
16
|
+
str += " and delay #{@delay}" if @delay
|
17
|
+
str += " and limit #{@limit}" if @limit
|
18
|
+
str
|
19
|
+
end
|
20
|
+
failure_message_when_negated { |actual| "expected #{actual} not to be rescueable with #{expected}" }
|
21
|
+
|
22
|
+
chain :with_delay do |delay|
|
23
|
+
@delay = delay
|
24
|
+
end
|
25
|
+
|
26
|
+
chain :with_limit do |limit|
|
27
|
+
@limit = limit
|
28
|
+
end
|
29
|
+
|
30
|
+
match do |actual|
|
31
|
+
actual.is_a?(Class) &&
|
32
|
+
actual.include?(Sidekiq::Rescue::Dsl) &&
|
33
|
+
actual.sidekiq_rescue_options[:error].include?(expected) &&
|
34
|
+
(@delay.nil? || actual.sidekiq_rescue_options[:delay] == @delay) &&
|
35
|
+
(@limit.nil? || actual.sidekiq_rescue_options[:limit] == @limit)
|
36
|
+
end
|
37
|
+
|
38
|
+
match_when_negated do |actual|
|
39
|
+
raise NotImplementedError, "it's confusing to use `not_to be_rescueable` with `with_delay`" if @delay
|
40
|
+
raise NotImplementedError, "it's confusing to use `not_to be_rescueable` with `with_limit`" if @limit
|
41
|
+
|
42
|
+
actual.is_a?(Class) &&
|
43
|
+
actual.include?(Sidekiq::Rescue::Dsl) &&
|
44
|
+
!actual.sidekiq_rescue_options[:error].include?(expected)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/sidekiq_rescue.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-rescue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitrii Ivliev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- lib/sidekiq/rescue.rb
|
40
40
|
- lib/sidekiq/rescue/config.rb
|
41
41
|
- lib/sidekiq/rescue/dsl.rb
|
42
|
+
- lib/sidekiq/rescue/rspec/matchers.rb
|
42
43
|
- lib/sidekiq/rescue/server_middleware.rb
|
43
44
|
- lib/sidekiq/rescue/version.rb
|
44
45
|
- lib/sidekiq_rescue.rb
|
@@ -49,7 +50,7 @@ metadata:
|
|
49
50
|
homepage_uri: https://github.com/moofkit/sidekiq-rescue
|
50
51
|
source_code_uri: https://github.com/moofkit/sidekiq-rescue
|
51
52
|
changelog_uri: https://github.com/moofkit/sidekiq-rescue/blob/master/CHANGELOG.md
|
52
|
-
documentation_uri: https://rubydoc.info/gems/sidekiq-rescue/0.2.
|
53
|
+
documentation_uri: https://rubydoc.info/gems/sidekiq-rescue/0.2.1
|
53
54
|
rubygems_mfa_required: 'true'
|
54
55
|
post_install_message:
|
55
56
|
rdoc_options: []
|