sidekiq-poison-pill-remedy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 605930770e6feca4c2a522fb9e4470c2d5e60e33c7ef105f6d246de851afa586
4
+ data.tar.gz: bb34229844977f3233a5ffc0f3a368ee59b2f1e8c917611139564d6b0fee6f5a
5
+ SHA512:
6
+ metadata.gz: 31049fa306e9d54bae85bbde4b2a78f2a19ee82d9c74c5a92bae3ddf6d94b94c6e89f325e6fd7374eccdd1dcf8abe2e63635810d20c37af372bf7e6663c902b8
7
+ data.tar.gz: 0a5c4a97360716ffaf39287a666470cba3c58e4b910e9b720b66634fe2f9b7c9c6d380d0ce3003aadcebbf981cc723f5d52046df4af6933565475fa9c971b30a
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,115 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rspec
4
+
5
+ inherit_mode:
6
+ merge:
7
+ - Exclude
8
+
9
+ AllCops:
10
+ NewCops: enable
11
+ TargetRubyVersion: 3.1
12
+ Exclude:
13
+ - "db/**/*"
14
+ - "bin/**/*"
15
+ - "tmp/**/*"
16
+ - "log/**/*"
17
+ - "vendor/**/*"
18
+ - "spec/rails_helper.rb"
19
+
20
+ Layout/FrozenStringLiteralComment:
21
+ Enabled: true
22
+
23
+ Layout/ArgumentAlignment:
24
+ EnforcedStyle: with_fixed_indentation
25
+
26
+ Layout/ArrayAlignment:
27
+ EnforcedStyle: with_fixed_indentation
28
+
29
+ Layout/EmptyLineBetweenDefs:
30
+ AllowAdjacentOneLineDefs: true
31
+
32
+ Layout/EndAlignment:
33
+ EnforcedStyleAlignWith: variable
34
+
35
+ Layout/FirstArgumentIndentation:
36
+ EnforcedStyle: consistent
37
+
38
+ Layout/FirstArrayElementIndentation:
39
+ EnforcedStyle: consistent
40
+
41
+ Layout/FirstHashElementIndentation:
42
+ EnforcedStyle: consistent
43
+
44
+ Layout/MultilineMethodCallIndentation:
45
+ EnforcedStyle: indented
46
+
47
+ Layout/MultilineOperationIndentation:
48
+ EnforcedStyle: indented
49
+
50
+ Layout/ParameterAlignment:
51
+ EnforcedStyle: with_fixed_indentation
52
+
53
+ Layout/SpaceBeforeBrackets:
54
+ Enabled: false
55
+
56
+
57
+ Lint/UnusedMethodArgument:
58
+ AllowUnusedKeywordArguments: true
59
+
60
+ Lint/AmbiguousBlockAssociation:
61
+ Exclude:
62
+ - 'spec/**/*'
63
+
64
+
65
+ Naming/FileName:
66
+ EnforcedStyle: snake_case
67
+ Exclude:
68
+ - 'lib/sidekiq-poison-pill-remedy.rb'
69
+
70
+ Naming/VariableNumber:
71
+ EnforcedStyle: snake_case
72
+
73
+
74
+ RSpec/MultipleExpectations:
75
+ Max: 20
76
+
77
+ RSpec/NestedGroups:
78
+ Max: 10
79
+
80
+ RSpec/ExampleLength:
81
+ Max: 15
82
+ Exclude:
83
+ - 'spec/sidekiq_poison_pill_remedy_spec.rb'
84
+
85
+ RSpec/VerifiedDoubles:
86
+ Exclude:
87
+ - 'spec/**/*.rb'
88
+
89
+
90
+ Metrics/AbcSize:
91
+ Max: 15
92
+ Exclude:
93
+ - 'lib/sidekiq_poison_pill_remedy.rb'
94
+
95
+
96
+ Metrics/MethodLength:
97
+ Max: 20
98
+
99
+ Metrics/BlockLength:
100
+ Exclude:
101
+ - 'lib/sidekiq_poison_pill_remedy.rb'
102
+
103
+ Layout/LineLength:
104
+ Max: 125
105
+
106
+
107
+ Style/StringLiterals:
108
+ EnforcedStyle: double_quotes
109
+ ConsistentQuotesInMultiline: true
110
+
111
+ Style/Documentation:
112
+ Enabled: false
113
+
114
+ RSpec/AnyInstance:
115
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-10-29
4
+
5
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Karol Galanciak
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.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # SidekiqPoisonPillRemedy
2
+
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.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ `gem 'sidekiq-poison-pill-remedy'`
10
+
11
+ And then execute:
12
+
13
+ `$ bundle install`
14
+
15
+ Or install it yourself as:
16
+
17
+ `$ gem install sidekiq-poison-pill-remedy`
18
+
19
+ ## Usage
20
+
21
+ The gem is supposed to be used in the following way when added to the application
22
+
23
+ Check Sidekiq super_fetch:[here](https://github.com/sidekiq/sidekiq/wiki/Reliability#using-super_fetch)
24
+
25
+ Remedy is supposed to be use like:
26
+ `config.super_fetch!(&SidekiqPoisonPillRemedy.remedy)`
27
+
28
+ When a job is considered a poison pill by Sidekiq, SidekiqPoisonPillRemedy prevents it from being moved to DeadSet and moves it to a dedicated queue to make sure the job will be processed after capturing team's attention with Sentry notification
29
+
30
+ ## Development
31
+
32
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
33
+
34
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/BookingSync/sidekiq-poison-pill-remedy.
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
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
+ task default: :spec
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sidekiq_poison_pill_remedy"
4
+ require "active_support"
5
+ require "active_support/inflector"
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SidekiqPoisonPillRemedy
4
+ def self.remedy
5
+ proc do |_jobstr, pill|
6
+ next unless pill
7
+
8
+ job = Sidekiq::DeadSet.new.find_job(pill.jid)
9
+
10
+ if job.queue == "poison_pill"
11
+ capture_sentry_message(
12
+ "#{job.klass} failed in the `#{job.queue}`, this means that it has to be urgently optimized on memory usage",
13
+ level: :critical,
14
+ job_item: job.item
15
+ )
16
+ else
17
+ capture_sentry_message(
18
+ "#{job.klass} was marked as `poison pill`, please create the job memory optimizations ticket timely",
19
+ level: :warning,
20
+ job_item: job.item
21
+ )
22
+ job.klass.constantize.set(queue: :poison_pill).perform_async(*job.args)
23
+ job.delete
24
+ end
25
+ end
26
+ end
27
+
28
+ def self.capture_sentry_message(message, level:, job_item:)
29
+ if defined?(Sentry)
30
+ Sentry.capture_message(
31
+ message,
32
+ level:,
33
+ extra: { job_item: }
34
+ )
35
+ end
36
+
37
+ Sidekiq.logger.fatal(message)
38
+ end
39
+ end
data/lib/version.rb ADDED
@@ -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
@@ -0,0 +1,10 @@
1
+ module Sidekiq
2
+ module Poison
3
+ module Pill
4
+ module Remedy
5
+ VERSION: String
6
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
7
+ end
8
+ end
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sidekiq-poison-pill-remedy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Karol Galanciak
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-10-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '6.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '6.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sidekiq
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Enhances Sidekiq's job processing by automatically handling and rescheduling
42
+ poison pills
43
+ email:
44
+ - karol.galanciak@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".rspec"
50
+ - ".rubocop.yml"
51
+ - CHANGELOG.md
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - lib/sidekiq-poison-pill-remedy.rb
56
+ - lib/sidekiq_poison_pill_remedy.rb
57
+ - lib/version.rb
58
+ - sig/sidekiq/poison/pill/remedy.rbs
59
+ homepage: https://github.com/BookingSync/sidekiq-poison-pill-remedy
60
+ licenses:
61
+ - MIT
62
+ metadata:
63
+ homepage_uri: https://github.com/BookingSync/sidekiq-poison-pill-remedy
64
+ source_code_uri: https://github.com/BookingSync/sidekiq-poison-pill-remedy
65
+ changelog_uri: https://github.com/BookingSync/sidekiq-poison-pill-remedy/blob/master/CHANGELOG.md
66
+ rubygems_mfa_required: 'true'
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 3.1.0
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubygems_version: 3.5.16
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Enhances Sidekiq's job processing by automatically handling and rescheduling
86
+ poison pills
87
+ test_files: []