-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 07f0c04
Showing
36 changed files
with
1,077 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Ruby | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
pull_request: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
name: Ruby ${{ matrix.ruby }} | ||
strategy: | ||
matrix: | ||
ruby: | ||
- '2.7' | ||
- '3.0' | ||
- '3.1' | ||
- '3.2' | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: ${{ matrix.ruby }} | ||
bundler-cache: true | ||
- name: Run tests | ||
run: make test | ||
- name: Run lints | ||
run: make lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/.bundle/ | ||
/.yardoc | ||
/_yardoc/ | ||
/coverage/ | ||
/doc/ | ||
/pkg/ | ||
/spec/reports/ | ||
/tmp/ | ||
|
||
# rspec failure tracking | ||
.rspec_status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--format documentation | ||
--color | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require: | ||
- rubocop-rake | ||
|
||
AllCops: | ||
TargetRubyVersion: 2.7 | ||
NewCops: enable | ||
|
||
Style/StringLiterals: | ||
Enabled: true | ||
EnforcedStyle: double_quotes | ||
|
||
Style/StringLiteralsInInterpolation: | ||
Enabled: true | ||
EnforcedStyle: double_quotes | ||
|
||
Layout/LineLength: | ||
Max: 120 | ||
|
||
Naming/FileName: | ||
Exclude: ['lib/sidekiq-rescue.rb'] | ||
|
||
Style/FrozenStringLiteralComment: | ||
Exclude: | ||
- 'gemfiles/**/*' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
appraise "sidekiq-6.5.x" do | ||
group :test do | ||
gem "sidekiq", "~> 6.5.0" | ||
end | ||
end | ||
|
||
appraise "sidekiq-7.0.x" do | ||
group :test do | ||
gem "sidekiq", "~> 7.0.0" | ||
end | ||
end | ||
|
||
appraise "sidekiq-7.1.x" do | ||
group :test do | ||
gem "sidekiq", "~> 7.1.0" | ||
end | ||
end | ||
|
||
appraise "sidekiq-7.2.x" do | ||
group :test do | ||
gem "sidekiq", "~> 7.2.0" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## [Unreleased] | ||
|
||
## [0.1.0] - 2023-12-27 | ||
|
||
- Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
source "https://rubygems.org" | ||
|
||
# Specify your gem's dependencies in sidekiq_rescue.gemspec | ||
gemspec | ||
|
||
gem "appraisal" | ||
gem "rake", "~> 13.0" | ||
|
||
gem "rspec", "~> 3.0" | ||
|
||
gem "rubocop", "~> 1.21" | ||
gem "rubocop-rake" | ||
gem "rubocop-rspec" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
sidekiq_rescue (0.1.0) | ||
sidekiq (>= 6.5) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
appraisal (2.5.0) | ||
bundler | ||
rake | ||
thor (>= 0.14.0) | ||
ast (2.4.2) | ||
concurrent-ruby (1.2.2) | ||
connection_pool (2.4.1) | ||
diff-lcs (1.5.0) | ||
json (2.7.1) | ||
language_server-protocol (3.17.0.3) | ||
parallel (1.24.0) | ||
parser (3.2.2.4) | ||
ast (~> 2.4.1) | ||
racc | ||
racc (1.7.3) | ||
rack (3.0.8) | ||
rainbow (3.1.1) | ||
rake (13.1.0) | ||
redis-client (0.19.1) | ||
connection_pool | ||
regexp_parser (2.8.3) | ||
rexml (3.2.6) | ||
rspec (3.12.0) | ||
rspec-core (~> 3.12.0) | ||
rspec-expectations (~> 3.12.0) | ||
rspec-mocks (~> 3.12.0) | ||
rspec-core (3.12.2) | ||
rspec-support (~> 3.12.0) | ||
rspec-expectations (3.12.3) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.12.0) | ||
rspec-mocks (3.12.6) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.12.0) | ||
rspec-support (3.12.1) | ||
rubocop (1.59.0) | ||
json (~> 2.3) | ||
language_server-protocol (>= 3.17.0) | ||
parallel (~> 1.10) | ||
parser (>= 3.2.2.4) | ||
rainbow (>= 2.2.2, < 4.0) | ||
regexp_parser (>= 1.8, < 3.0) | ||
rexml (>= 3.2.5, < 4.0) | ||
rubocop-ast (>= 1.30.0, < 2.0) | ||
ruby-progressbar (~> 1.7) | ||
unicode-display_width (>= 2.4.0, < 3.0) | ||
rubocop-ast (1.30.0) | ||
parser (>= 3.2.1.0) | ||
rubocop-capybara (2.19.0) | ||
rubocop (~> 1.41) | ||
rubocop-factory_bot (2.24.0) | ||
rubocop (~> 1.33) | ||
rubocop-rake (0.6.0) | ||
rubocop (~> 1.0) | ||
rubocop-rspec (2.25.0) | ||
rubocop (~> 1.40) | ||
rubocop-capybara (~> 2.17) | ||
rubocop-factory_bot (~> 2.22) | ||
ruby-progressbar (1.13.0) | ||
sidekiq (7.2.0) | ||
concurrent-ruby (< 2) | ||
connection_pool (>= 2.3.0) | ||
rack (>= 2.2.4) | ||
redis-client (>= 0.14.0) | ||
thor (1.3.0) | ||
unicode-display_width (2.5.0) | ||
|
||
PLATFORMS | ||
x86_64-darwin-22 | ||
|
||
DEPENDENCIES | ||
appraisal | ||
rake (~> 13.0) | ||
rspec (~> 3.0) | ||
rubocop (~> 1.21) | ||
rubocop-rake | ||
rubocop-rspec | ||
sidekiq_rescue! | ||
|
||
BUNDLED WITH | ||
2.4.22 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2023 Dmitrii Ivliev | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
PHONY: test lint | ||
|
||
init: | ||
bundle install | ||
bundle exec appraisal generate | ||
bundle exec appraisal install | ||
|
||
test: | ||
bundle exec appraisal rake spec | ||
|
||
lint: | ||
bundle exec rubocop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# Sidekiq::Rescue | ||
|
||
[![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) | ||
|
||
[Sidekiq](https://github.com/sidekiq/sidekiq) plugin to rescue jobs from expected errors and retry them later. | ||
|
||
## Installation | ||
|
||
Add this line to your application's Gemfile: | ||
|
||
```ruby | ||
gem "sidekiq-rescue" | ||
``` | ||
|
||
And then execute: | ||
|
||
$ bundle install | ||
|
||
Or install it yourself as: | ||
|
||
$ gem install sidekiq-rescue | ||
|
||
## Usage | ||
|
||
1. Add the middleware to your Sidekiq configuration: | ||
|
||
```ruby | ||
Sidekiq.configure_server do |config| | ||
config.server_middleware do |chain| | ||
chain.add Sidekiq::Rescue::Middleware | ||
end | ||
end | ||
``` | ||
|
||
2. Add DSL to your job: | ||
|
||
```ruby | ||
class MyJob | ||
include Sidekiq::Job | ||
include Sidekiq::Rescue::DSL | ||
|
||
sidekiq_rescue ExpectedError | ||
|
||
def perform(*) | ||
# ... | ||
end | ||
end | ||
``` | ||
|
||
## Configuration | ||
|
||
You can configure the number of retries and the delay (in seconds) between retries: | ||
|
||
```ruby | ||
class MyJob | ||
include Sidekiq::Job | ||
include Sidekiq::Rescue::DSL | ||
|
||
sidekiq_rescue ExpectedError, delay: 60, limit: 5 | ||
|
||
def perform(*) | ||
# ... | ||
end | ||
end | ||
``` | ||
|
||
The default values are: | ||
- `delay`: 60 seconds | ||
- `limit`: 5 retries | ||
|
||
Delay does not increase between retries (unlike Sidekiq standard retry mechanism). | ||
|
||
## Use cases | ||
|
||
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. | ||
|
||
## Motivation | ||
|
||
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. | ||
In addition, it provides a way to configure the number of retries and the delay between retries independently from the Sidekiq standard retry mechanism. | ||
|
||
## Supported Ruby versions | ||
|
||
This gem supports Ruby 2.7+ | ||
|
||
If something doesn't work on one of these versions, it's a bug | ||
|
||
## Supported Sidekiq versions | ||
|
||
This gem supports Sidekiq 6.5+. It may work with older versions, but it's not tested. | ||
|
||
If you need support for older versions, please open an issue | ||
|
||
## Development | ||
|
||
To install dependencies and run tests: | ||
```bash | ||
make init | ||
make test | ||
make lint | ||
``` | ||
|
||
## Contributing | ||
|
||
Bug reports and pull requests are welcome on GitHub at https://github.com/moofkit/sidekiq_rescue. | ||
|
||
## License | ||
|
||
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
require "bundler/gem_tasks" | ||
require "rspec/core/rake_task" | ||
|
||
RSpec::Core::RakeTask.new(:spec) | ||
|
||
require "rubocop/rake_task" | ||
|
||
RuboCop::RakeTask.new | ||
|
||
task default: %i[spec rubocop] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require "bundler/setup" | ||
require "sidekiq_rescue" | ||
|
||
# You can add fixtures and/or initialization code here to make experimenting | ||
# with your gem easier. You can also use a different console, if you like. | ||
|
||
require "irb" | ||
IRB.start(__FILE__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
IFS=$'\n\t' | ||
set -vx | ||
|
||
bundle install | ||
|
||
# Do any other automated setup that you need to do here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
BUNDLE_RETRY: "1" |
Oops, something went wrong.