Skip to content

Commit 638da27

Browse files
feat: add interruption adapter for shoryuken
1 parent 015df7d commit 638da27

6 files changed

Lines changed: 65 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ nil
1010

1111
### Features
1212

13-
nil
13+
- Add interruption adapter for [Shoryuken](https://github.com/ruby-shoryuken/shoryuken).
1414

1515
### Bug fixes
1616

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ end
2828
gem "sidekiq", sidekiq_version
2929
gem "resque", resque_version
3030
gem "delayed_job"
31+
gem "shoryuken"
3132
gem "connection_pool", connection_pool_version
3233

3334
if defined?(@rails_gems_requirements) && @rails_gems_requirements

Gemfile.lock

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,21 @@ GEM
5353
tzinfo (~> 2.0, >= 2.0.5)
5454
uri (>= 0.13.1)
5555
ast (2.4.3)
56+
aws-eventstream (1.4.0)
57+
aws-partitions (1.1258.0)
58+
aws-sdk-core (3.251.0)
59+
aws-eventstream (~> 1, >= 1.3.0)
60+
aws-partitions (~> 1, >= 1.992.0)
61+
aws-sigv4 (~> 1.9)
62+
base64
63+
bigdecimal
64+
jmespath (~> 1, >= 1.6.1)
65+
logger
66+
aws-sdk-sqs (1.116.0)
67+
aws-sdk-core (~> 3, >= 3.248.0)
68+
aws-sigv4 (~> 1.5)
69+
aws-sigv4 (1.12.1)
70+
aws-eventstream (~> 1, >= 1.0.2)
5671
base64 (0.3.0)
5772
benchmark (0.5.0)
5873
bigdecimal (3.3.1)
@@ -77,6 +92,7 @@ GEM
7792
pp (>= 0.6.0)
7893
rdoc (>= 4.0.0)
7994
reline (>= 0.4.2)
95+
jmespath (1.6.2)
8096
json (2.16.0)
8197
language_server-protocol (3.17.0.5)
8298
lint_roller (1.1.0)
@@ -196,6 +212,11 @@ GEM
196212
rubydex (0.1.0.beta13-x86_64-darwin)
197213
rubydex (0.1.0.beta13-x86_64-linux)
198214
securerandom (0.4.1)
215+
shoryuken (7.0.2)
216+
aws-sdk-sqs (>= 1.66.0)
217+
concurrent-ruby
218+
thor
219+
zeitwerk (~> 2.6)
199220
sidekiq (8.0.10)
200221
connection_pool (>= 2.5.0)
201222
json (>= 2.9.0)
@@ -275,6 +296,7 @@ DEPENDENCIES
275296
redis
276297
resque (>= 3.0.0)
277298
rubocop-shopify
299+
shoryuken
278300
sidekiq (>= 8.0.9)
279301
sorbet-runtime (>= 0.6.12698)
280302
tapioca (>= 0.19.1)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ Job-iteration currently supports the following queue adapters (in order of imple
178178
- [Solid Queue](https://github.com/rails/solid_queue)
179179
- [Amazon SQS](https://github.com/aws/aws-activejob-sqs-ruby)
180180
- [Delayed::Job](https://github.com/collectiveidea/delayed_job)
181+
- [Shoryuken](https://github.com/ruby-shoryuken/shoryuken)
181182

182183
It supports the following platforms:
183184

lib/job-iteration/interruption_adapters.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
module JobIteration
66
module InterruptionAdapters
7-
BUNDLED_ADAPTERS = [:delayed_job, :good_job, :resque, :sidekiq, :solid_queue, :sqs].freeze # @api private
7+
BUNDLED_ADAPTERS = [:delayed_job, :good_job, :resque, :shoryuken, :sidekiq, :solid_queue, :sqs].freeze # @api private
88

99
class << self
1010
# Returns adapter for specified name.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# frozen_string_literal: true
2+
3+
begin
4+
require "shoryuken"
5+
rescue LoadError
6+
# Shoryuken is not available, no need to load the adapter
7+
return
8+
end
9+
10+
begin
11+
# Lifecycle event registration (Shoryuken.configure_server / config.on) was
12+
# introduced in Shoryuken 2.0.2.
13+
gem("shoryuken", ">= 2.0.2")
14+
rescue Gem::LoadError
15+
warn("job-iteration's interruption adapter for Shoryuken requires Shoryuken 2.0.2 or newer")
16+
return
17+
end
18+
19+
module JobIteration
20+
module InterruptionAdapters
21+
module ShoryukenAdapter
22+
class << self
23+
attr_accessor :stopping
24+
25+
def call
26+
stopping
27+
end
28+
end
29+
30+
Shoryuken.configure_server do |config|
31+
config.on(:shutdown) do
32+
ShoryukenAdapter.stopping = true
33+
end
34+
end
35+
end
36+
37+
register(:shoryuken, ShoryukenAdapter)
38+
end
39+
end

0 commit comments

Comments
 (0)