Skip to content

Commit 3f61386

Browse files
committed
remedy logic, gemfile, gemspec, CI
1 parent 5279830 commit 3f61386

File tree

12 files changed

+203
-51
lines changed

12 files changed

+203
-51
lines changed

.github/workflows/ci.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: CI
2+
on: [pull_request, push]
3+
jobs:
4+
rubocop:
5+
strategy:
6+
fail-fast: true
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- uses: ruby/setup-ruby@v1
11+
with:
12+
ruby-version: 3.1
13+
bundler-cache: true
14+
- run: bundle exec rubocop
15+
rspec:
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
ruby: ['3.1', '3.2', '3.3']
20+
runs-on: ubuntu-latest
21+
services:
22+
redis:
23+
image: redis
24+
ports:
25+
- 6379:6379
26+
options: >-
27+
--health-cmd "redis-cli ping"
28+
--health-interval 10s
29+
--health-timeout 5s
30+
--health-retries 5
31+
steps:
32+
- uses: actions/checkout@v2
33+
- uses: ruby/setup-ruby@v1
34+
with:
35+
ruby-version: ${{ matrix.ruby }}
36+
bundler-cache: true
37+
- run: bundle exec rake

Gemfile

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,10 @@ source "https://rubygems.org"
66
gemspec
77

88
gem "rake", "~> 13.0"
9-
109
gem "rspec", "~> 3.0"
10+
gem 'rubocop', '~> 1.40', require: false
11+
gem "rubocop-performance"
12+
gem "rubocop-rake"
13+
gem "rubocop-rspec"
14+
gem 'sidekiq'
15+
gem 'sentry-ruby'

Gemfile.lock

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
PATH
2+
remote: .
3+
specs:
4+
sidekiq-poison-pill-remedy (0.1.0)
5+
6+
GEM
7+
remote: https://rubygems.org/
8+
specs:
9+
ast (2.4.2)
10+
bigdecimal (3.1.8)
11+
concurrent-ruby (1.3.4)
12+
connection_pool (2.4.1)
13+
diff-lcs (1.5.1)
14+
json (2.7.2)
15+
language_server-protocol (3.17.0.3)
16+
logger (1.6.1)
17+
parallel (1.26.3)
18+
parser (3.3.5.0)
19+
ast (~> 2.4.1)
20+
racc
21+
racc (1.8.1)
22+
rack (3.1.7)
23+
rainbow (3.1.1)
24+
rake (13.2.1)
25+
redis-client (0.22.2)
26+
connection_pool
27+
regexp_parser (2.9.2)
28+
rspec (3.13.0)
29+
rspec-core (~> 3.13.0)
30+
rspec-expectations (~> 3.13.0)
31+
rspec-mocks (~> 3.13.0)
32+
rspec-core (3.13.1)
33+
rspec-support (~> 3.13.0)
34+
rspec-expectations (3.13.3)
35+
diff-lcs (>= 1.2.0, < 2.0)
36+
rspec-support (~> 3.13.0)
37+
rspec-mocks (3.13.2)
38+
diff-lcs (>= 1.2.0, < 2.0)
39+
rspec-support (~> 3.13.0)
40+
rspec-support (3.13.1)
41+
rubocop (1.66.1)
42+
json (~> 2.3)
43+
language_server-protocol (>= 3.17.0)
44+
parallel (~> 1.10)
45+
parser (>= 3.3.0.2)
46+
rainbow (>= 2.2.2, < 4.0)
47+
regexp_parser (>= 2.4, < 3.0)
48+
rubocop-ast (>= 1.32.2, < 2.0)
49+
ruby-progressbar (~> 1.7)
50+
unicode-display_width (>= 2.4.0, < 3.0)
51+
rubocop-ast (1.32.3)
52+
parser (>= 3.3.1.0)
53+
rubocop-performance (1.22.1)
54+
rubocop (>= 1.48.1, < 2.0)
55+
rubocop-ast (>= 1.31.1, < 2.0)
56+
rubocop-rake (0.6.0)
57+
rubocop (~> 1.0)
58+
rubocop-rspec (3.1.0)
59+
rubocop (~> 1.61)
60+
ruby-progressbar (1.13.0)
61+
sentry-ruby (5.21.0)
62+
bigdecimal
63+
concurrent-ruby (~> 1.0, >= 1.0.2)
64+
sidekiq (7.3.2)
65+
concurrent-ruby (< 2)
66+
connection_pool (>= 2.3.0)
67+
logger
68+
rack (>= 2.2.4)
69+
redis-client (>= 0.22.2)
70+
unicode-display_width (2.6.0)
71+
72+
PLATFORMS
73+
arm64-darwin-22
74+
75+
DEPENDENCIES
76+
rake (~> 13.0)
77+
rspec (~> 3.0)
78+
rubocop (~> 1.40)
79+
rubocop-performance
80+
rubocop-rake
81+
rubocop-rspec
82+
sentry-ruby
83+
sidekiq
84+
sidekiq-poison-pill-remedy!
85+
86+
BUNDLED WITH
87+
2.4.18

README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
# Sidekiq::Poison::Pill::Remedy
1+
# SidekiqPoisonPillRemedy
22

3-
TODO: Delete this and the text below, and describe your gem
4-
5-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sidekiq/poison/pill/remedy`. To experiment with that code, run `bin/console` for an interactive prompt.
3+
The Sidekiq Poison Pill Remedy gem enhances Sidekiq's job processing by automatically handling and rescheduling failed jobs (poison pills) with integrated logging and error tracking through Sentry, ultimately improving reliability and performance optimization.
64

75
## Installation
86

lib/remedy/version.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
module SidekiqPoisonPillRemedy
4+
module Version
5+
end
6+
VERSION = '0.1.0'
7+
end

lib/sidekiq/poison/pill/remedy.rb

-14
This file was deleted.

lib/sidekiq/poison/pill/remedy/version.rb

-11
This file was deleted.

lib/sidekiq_poison_pill_remedy.rb

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "../lib/remedy/version"
4+
5+
module SidekiqPoisonPillRemedy
6+
def self.remedy
7+
Proc.new do |_jobstr, pill|
8+
next unless pill
9+
10+
job = Sidekiq::DeadSet.new.find_job(pill.jid)
11+
12+
if job.queue == "poison_pill"
13+
capture_sentry_message(
14+
"#{job.klass} failed in the `#{job.queue}`, this means that it has to be urgently optimized on memory usage",
15+
level: :critical,
16+
job_item: job.item
17+
)
18+
else
19+
capture_sentry_message(
20+
"#{job.klass} was marked as `poison pill`, please create the job memory optimizations ticket timely",
21+
level: :warning,
22+
job_item: job.item
23+
)
24+
job.klass.constantize.set(queue: :poison_pill).perform_async(*job.args)
25+
job.delete
26+
end
27+
end
28+
end
29+
30+
def self.capture_sentry_message(message, level:, job_item:)
31+
if defined?(Sentry)
32+
Sentry.capture_message(
33+
message,
34+
level: level,
35+
extra: { job_item: job_item }
36+
)
37+
end
38+
39+
Sidekiq.logger.fatal(message)
40+
end
41+
end

sidekiq-poison-pill-remedy.gemspec

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
# frozen_string_literal: true
22

3-
require_relative "lib/sidekiq/poison/pill/remedy/version"
3+
require_relative "lib/remedy/version"
44

55
Gem::Specification.new do |spec|
66
spec.name = "sidekiq-poison-pill-remedy"
7-
spec.version = Sidekiq::Poison::Pill::Remedy::VERSION
7+
spec.version = SidekiqPoisonPillRemedy::VERSION
88
spec.authors = ["Karol Galanciak"]
99
spec.email = ["[email protected]"]
1010

11-
spec.summary = "TODO: Write a short summary, because RubyGems requires one."
12-
spec.description = "TODO: Write a longer description or delete this line."
13-
spec.homepage = "TODO: Put your gem's website or public repo URL here."
11+
spec.summary = "Enhances Sidekiq's job processing by automatically handling and rescheduling failed jobs (poison pills)"
12+
spec.description = "Enhances Sidekiq's job processing by automatically handling and rescheduling failed jobs (poison pills)"
13+
spec.homepage = "https://example.com"
1414
spec.license = "MIT"
1515
spec.required_ruby_version = ">= 3.0.0"
1616

17-
spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
17+
# spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
1818

1919
spec.metadata["homepage_uri"] = spec.homepage
20-
spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
21-
spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
20+
spec.metadata["source_code_uri"] = "https://example.com"
21+
spec.metadata["changelog_uri"] = "https://example.com"
2222

2323
# Specify which files should be added to the gem when it is released.
2424
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.

spec/sidekiq/poison/pill/remedy_spec.rb

-11
This file was deleted.
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../lib/sidekiq_poison_pill_remedy'
4+
5+
RSpec.describe SidekiqPoisonPillRemedy do
6+
it 'has a version number' do
7+
expect(SidekiqPoisonPillRemedy::VERSION).not_to be nil
8+
end
9+
10+
it 'does something useful' do
11+
expect(false).to eq(true)
12+
end
13+
end

spec/spec_helper.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# frozen_string_literal: true
22

3-
require "sidekiq/poison/pill/remedy"
3+
require_relative '../lib/sidekiq_poison_pill_remedy'
44

55
RSpec.configure do |config|
66
# Enable flags like --only-failures and --next-failure
7-
config.example_status_persistence_file_path = ".rspec_status"
7+
config.example_status_persistence_file_path = '.rspec_status'
88

99
# Disable RSpec exposing methods globally on `Module` and `main`
1010
config.disable_monkey_patching!

0 commit comments

Comments
 (0)