Skip to content

Commit 07f0c04

Browse files
committed
init repo
0 parents  commit 07f0c04

36 files changed

+1077
-0
lines changed

.github/workflows/main.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Ruby
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
pull_request:
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
name: Ruby ${{ matrix.ruby }}
14+
strategy:
15+
matrix:
16+
ruby:
17+
- '2.7'
18+
- '3.0'
19+
- '3.1'
20+
- '3.2'
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
- name: Set up Ruby
25+
uses: ruby/setup-ruby@v1
26+
with:
27+
ruby-version: ${{ matrix.ruby }}
28+
bundler-cache: true
29+
- name: Run tests
30+
run: make test
31+
- name: Run lints
32+
run: make lint

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/.bundle/
2+
/.yardoc
3+
/_yardoc/
4+
/coverage/
5+
/doc/
6+
/pkg/
7+
/spec/reports/
8+
/tmp/
9+
10+
# rspec failure tracking
11+
.rspec_status

.rspec

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--format documentation
2+
--color
3+
--require spec_helper

.rubocop.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require:
2+
- rubocop-rake
3+
4+
AllCops:
5+
TargetRubyVersion: 2.7
6+
NewCops: enable
7+
8+
Style/StringLiterals:
9+
Enabled: true
10+
EnforcedStyle: double_quotes
11+
12+
Style/StringLiteralsInInterpolation:
13+
Enabled: true
14+
EnforcedStyle: double_quotes
15+
16+
Layout/LineLength:
17+
Max: 120
18+
19+
Naming/FileName:
20+
Exclude: ['lib/sidekiq-rescue.rb']
21+
22+
Style/FrozenStringLiteralComment:
23+
Exclude:
24+
- 'gemfiles/**/*'

Appraisals

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
appraise "sidekiq-6.5.x" do
4+
group :test do
5+
gem "sidekiq", "~> 6.5.0"
6+
end
7+
end
8+
9+
appraise "sidekiq-7.0.x" do
10+
group :test do
11+
gem "sidekiq", "~> 7.0.0"
12+
end
13+
end
14+
15+
appraise "sidekiq-7.1.x" do
16+
group :test do
17+
gem "sidekiq", "~> 7.1.0"
18+
end
19+
end
20+
21+
appraise "sidekiq-7.2.x" do
22+
group :test do
23+
gem "sidekiq", "~> 7.2.0"
24+
end
25+
end

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## [Unreleased]
2+
3+
## [0.1.0] - 2023-12-27
4+
5+
- Initial release

Gemfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
# Specify your gem's dependencies in sidekiq_rescue.gemspec
6+
gemspec
7+
8+
gem "appraisal"
9+
gem "rake", "~> 13.0"
10+
11+
gem "rspec", "~> 3.0"
12+
13+
gem "rubocop", "~> 1.21"
14+
gem "rubocop-rake"
15+
gem "rubocop-rspec"

Gemfile.lock

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
PATH
2+
remote: .
3+
specs:
4+
sidekiq_rescue (0.1.0)
5+
sidekiq (>= 6.5)
6+
7+
GEM
8+
remote: https://rubygems.org/
9+
specs:
10+
appraisal (2.5.0)
11+
bundler
12+
rake
13+
thor (>= 0.14.0)
14+
ast (2.4.2)
15+
concurrent-ruby (1.2.2)
16+
connection_pool (2.4.1)
17+
diff-lcs (1.5.0)
18+
json (2.7.1)
19+
language_server-protocol (3.17.0.3)
20+
parallel (1.24.0)
21+
parser (3.2.2.4)
22+
ast (~> 2.4.1)
23+
racc
24+
racc (1.7.3)
25+
rack (3.0.8)
26+
rainbow (3.1.1)
27+
rake (13.1.0)
28+
redis-client (0.19.1)
29+
connection_pool
30+
regexp_parser (2.8.3)
31+
rexml (3.2.6)
32+
rspec (3.12.0)
33+
rspec-core (~> 3.12.0)
34+
rspec-expectations (~> 3.12.0)
35+
rspec-mocks (~> 3.12.0)
36+
rspec-core (3.12.2)
37+
rspec-support (~> 3.12.0)
38+
rspec-expectations (3.12.3)
39+
diff-lcs (>= 1.2.0, < 2.0)
40+
rspec-support (~> 3.12.0)
41+
rspec-mocks (3.12.6)
42+
diff-lcs (>= 1.2.0, < 2.0)
43+
rspec-support (~> 3.12.0)
44+
rspec-support (3.12.1)
45+
rubocop (1.59.0)
46+
json (~> 2.3)
47+
language_server-protocol (>= 3.17.0)
48+
parallel (~> 1.10)
49+
parser (>= 3.2.2.4)
50+
rainbow (>= 2.2.2, < 4.0)
51+
regexp_parser (>= 1.8, < 3.0)
52+
rexml (>= 3.2.5, < 4.0)
53+
rubocop-ast (>= 1.30.0, < 2.0)
54+
ruby-progressbar (~> 1.7)
55+
unicode-display_width (>= 2.4.0, < 3.0)
56+
rubocop-ast (1.30.0)
57+
parser (>= 3.2.1.0)
58+
rubocop-capybara (2.19.0)
59+
rubocop (~> 1.41)
60+
rubocop-factory_bot (2.24.0)
61+
rubocop (~> 1.33)
62+
rubocop-rake (0.6.0)
63+
rubocop (~> 1.0)
64+
rubocop-rspec (2.25.0)
65+
rubocop (~> 1.40)
66+
rubocop-capybara (~> 2.17)
67+
rubocop-factory_bot (~> 2.22)
68+
ruby-progressbar (1.13.0)
69+
sidekiq (7.2.0)
70+
concurrent-ruby (< 2)
71+
connection_pool (>= 2.3.0)
72+
rack (>= 2.2.4)
73+
redis-client (>= 0.14.0)
74+
thor (1.3.0)
75+
unicode-display_width (2.5.0)
76+
77+
PLATFORMS
78+
x86_64-darwin-22
79+
80+
DEPENDENCIES
81+
appraisal
82+
rake (~> 13.0)
83+
rspec (~> 3.0)
84+
rubocop (~> 1.21)
85+
rubocop-rake
86+
rubocop-rspec
87+
sidekiq_rescue!
88+
89+
BUNDLED WITH
90+
2.4.22

LICENSE.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2023 Dmitrii Ivliev
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

Makefile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
PHONY: test lint
2+
3+
init:
4+
bundle install
5+
bundle exec appraisal generate
6+
bundle exec appraisal install
7+
8+
test:
9+
bundle exec appraisal rake spec
10+
11+
lint:
12+
bundle exec rubocop

README.md

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Sidekiq::Rescue
2+
3+
[![Build Status](https://github.com/moofkit/sidekiq-rescue/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/moofkit/sidekiq-rescue/actions/workflows/main.yml)
4+
5+
[Sidekiq](https://github.com/sidekiq/sidekiq) plugin to rescue jobs from expected errors and retry them later.
6+
7+
## Installation
8+
9+
Add this line to your application's Gemfile:
10+
11+
```ruby
12+
gem "sidekiq-rescue"
13+
```
14+
15+
And then execute:
16+
17+
$ bundle install
18+
19+
Or install it yourself as:
20+
21+
$ gem install sidekiq-rescue
22+
23+
## Usage
24+
25+
1. Add the middleware to your Sidekiq configuration:
26+
27+
```ruby
28+
Sidekiq.configure_server do |config|
29+
config.server_middleware do |chain|
30+
chain.add Sidekiq::Rescue::Middleware
31+
end
32+
end
33+
```
34+
35+
2. Add DSL to your job:
36+
37+
```ruby
38+
class MyJob
39+
include Sidekiq::Job
40+
include Sidekiq::Rescue::DSL
41+
42+
sidekiq_rescue ExpectedError
43+
44+
def perform(*)
45+
# ...
46+
end
47+
end
48+
```
49+
50+
## Configuration
51+
52+
You can configure the number of retries and the delay (in seconds) between retries:
53+
54+
```ruby
55+
class MyJob
56+
include Sidekiq::Job
57+
include Sidekiq::Rescue::DSL
58+
59+
sidekiq_rescue ExpectedError, delay: 60, limit: 5
60+
61+
def perform(*)
62+
# ...
63+
end
64+
end
65+
```
66+
67+
The default values are:
68+
- `delay`: 60 seconds
69+
- `limit`: 5 retries
70+
71+
Delay does not increase between retries (unlike Sidekiq standard retry mechanism).
72+
73+
## Use cases
74+
75+
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.
76+
77+
## Motivation
78+
79+
Sidekiq provides a retry mechanism for jobs that failed due to unexpected errors. However, it does not provide a way to retry jobs that failed due to expected errors. This gem aims to fill this gap.
80+
In addition, it provides a way to configure the number of retries and the delay between retries independently from the Sidekiq standard retry mechanism.
81+
82+
## Supported Ruby versions
83+
84+
This gem supports Ruby 2.7+
85+
86+
If something doesn't work on one of these versions, it's a bug
87+
88+
## Supported Sidekiq versions
89+
90+
This gem supports Sidekiq 6.5+. It may work with older versions, but it's not tested.
91+
92+
If you need support for older versions, please open an issue
93+
94+
## Development
95+
96+
To install dependencies and run tests:
97+
```bash
98+
make init
99+
make test
100+
make lint
101+
```
102+
103+
## Contributing
104+
105+
Bug reports and pull requests are welcome on GitHub at https://github.com/moofkit/sidekiq_rescue.
106+
107+
## License
108+
109+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

Rakefile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
require "bundler/gem_tasks"
4+
require "rspec/core/rake_task"
5+
6+
RSpec::Core::RakeTask.new(:spec)
7+
8+
require "rubocop/rake_task"
9+
10+
RuboCop::RakeTask.new
11+
12+
task default: %i[spec rubocop]

bin/console

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require "bundler/setup"
5+
require "sidekiq_rescue"
6+
7+
# You can add fixtures and/or initialization code here to make experimenting
8+
# with your gem easier. You can also use a different console, if you like.
9+
10+
require "irb"
11+
IRB.start(__FILE__)

bin/setup

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
set -vx
5+
6+
bundle install
7+
8+
# Do any other automated setup that you need to do here

gemfiles/.bundle/config

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
BUNDLE_RETRY: "1"

0 commit comments

Comments
 (0)