shoryuken 7.0.0.alpha1 → 7.0.0.alpha2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/push.yml +3 -3
- data/.github/workflows/specs.yml +6 -9
- data/.github/workflows/verify-action-pins.yml +1 -1
- data/.rspec +2 -1
- data/.ruby-version +1 -1
- data/Appraisals +0 -6
- data/CHANGELOG.md +186 -142
- data/Gemfile +1 -0
- data/README.md +12 -13
- data/bin/cli/base.rb +1 -2
- data/bin/cli/sqs.rb +5 -4
- data/bin/shoryuken +2 -1
- data/gemfiles/rails_7_0.gemfile +10 -10
- data/gemfiles/rails_7_1.gemfile +10 -9
- data/gemfiles/rails_7_2.gemfile +10 -9
- data/gemfiles/rails_8_0.gemfile +10 -9
- data/lib/shoryuken/body_parser.rb +3 -1
- data/lib/shoryuken/client.rb +2 -0
- data/lib/shoryuken/default_exception_handler.rb +2 -0
- data/lib/shoryuken/default_worker_registry.rb +11 -11
- data/lib/shoryuken/environment_loader.rb +6 -6
- data/lib/shoryuken/extensions/active_job_adapter.rb +8 -6
- data/lib/shoryuken/extensions/active_job_concurrent_send_adapter.rb +5 -5
- data/lib/shoryuken/extensions/active_job_extensions.rb +2 -0
- data/lib/shoryuken/fetcher.rb +4 -2
- data/lib/shoryuken/helpers/atomic_boolean.rb +44 -0
- data/lib/shoryuken/helpers/atomic_counter.rb +104 -0
- data/lib/shoryuken/helpers/atomic_hash.rb +182 -0
- data/lib/shoryuken/helpers/hash_utils.rb +56 -0
- data/lib/shoryuken/helpers/string_utils.rb +65 -0
- data/lib/shoryuken/inline_message.rb +22 -0
- data/lib/shoryuken/launcher.rb +2 -0
- data/lib/shoryuken/logging.rb +19 -5
- data/lib/shoryuken/manager.rb +6 -4
- data/lib/shoryuken/message.rb +2 -0
- data/lib/shoryuken/middleware/chain.rb +2 -0
- data/lib/shoryuken/middleware/server/active_record.rb +2 -0
- data/lib/shoryuken/middleware/server/auto_delete.rb +2 -0
- data/lib/shoryuken/middleware/server/auto_extend_visibility.rb +10 -10
- data/lib/shoryuken/middleware/server/exponential_backoff_retry.rb +5 -3
- data/lib/shoryuken/middleware/server/timing.rb +2 -0
- data/lib/shoryuken/options.rb +9 -5
- data/lib/shoryuken/polling/base_strategy.rb +126 -0
- data/lib/shoryuken/polling/queue_configuration.rb +103 -0
- data/lib/shoryuken/polling/strict_priority.rb +2 -0
- data/lib/shoryuken/polling/weighted_round_robin.rb +2 -0
- data/lib/shoryuken/processor.rb +5 -2
- data/lib/shoryuken/queue.rb +6 -4
- data/lib/shoryuken/runner.rb +9 -12
- data/lib/shoryuken/util.rb +6 -6
- data/lib/shoryuken/version.rb +3 -1
- data/lib/shoryuken/worker/default_executor.rb +2 -0
- data/lib/shoryuken/worker/inline_executor.rb +3 -1
- data/lib/shoryuken/worker.rb +2 -0
- data/lib/shoryuken/worker_registry.rb +2 -0
- data/lib/shoryuken.rb +8 -28
- data/shoryuken.gemspec +6 -6
- data/spec/integration/launcher_spec.rb +2 -3
- data/spec/shared_examples_for_active_job.rb +13 -8
- data/spec/shoryuken/body_parser_spec.rb +1 -2
- data/spec/shoryuken/client_spec.rb +1 -1
- data/spec/shoryuken/default_exception_handler_spec.rb +9 -10
- data/spec/shoryuken/default_worker_registry_spec.rb +1 -2
- data/spec/shoryuken/environment_loader_spec.rb +9 -8
- data/spec/shoryuken/extensions/active_job_adapter_spec.rb +2 -1
- data/spec/shoryuken/extensions/active_job_base_spec.rb +2 -1
- data/spec/shoryuken/extensions/active_job_concurrent_send_adapter_spec.rb +2 -1
- data/spec/shoryuken/extensions/active_job_wrapper_spec.rb +2 -1
- data/spec/shoryuken/fetcher_spec.rb +23 -26
- data/spec/shoryuken/helpers/atomic_boolean_spec.rb +196 -0
- data/spec/shoryuken/helpers/atomic_counter_spec.rb +177 -0
- data/spec/shoryuken/helpers/atomic_hash_spec.rb +307 -0
- data/spec/shoryuken/helpers/hash_utils_spec.rb +145 -0
- data/spec/shoryuken/helpers/string_utils_spec.rb +124 -0
- data/spec/shoryuken/helpers_integration_spec.rb +96 -0
- data/spec/shoryuken/inline_message_spec.rb +196 -0
- data/spec/shoryuken/launcher_spec.rb +1 -2
- data/spec/shoryuken/manager_spec.rb +1 -2
- data/spec/shoryuken/middleware/chain_spec.rb +1 -1
- data/spec/shoryuken/middleware/server/auto_delete_spec.rb +1 -1
- data/spec/shoryuken/middleware/server/auto_extend_visibility_spec.rb +1 -1
- data/spec/shoryuken/middleware/server/exponential_backoff_retry_spec.rb +1 -1
- data/spec/shoryuken/middleware/server/timing_spec.rb +1 -1
- data/spec/shoryuken/options_spec.rb +4 -4
- data/spec/shoryuken/polling/base_strategy_spec.rb +280 -0
- data/spec/shoryuken/polling/queue_configuration_spec.rb +195 -0
- data/spec/shoryuken/polling/strict_priority_spec.rb +1 -1
- data/spec/shoryuken/polling/weighted_round_robin_spec.rb +1 -1
- data/spec/shoryuken/processor_spec.rb +1 -1
- data/spec/shoryuken/queue_spec.rb +2 -3
- data/spec/shoryuken/runner_spec.rb +1 -3
- data/spec/shoryuken/util_spec.rb +1 -1
- data/spec/shoryuken/worker/default_executor_spec.rb +1 -1
- data/spec/shoryuken/worker/inline_executor_spec.rb +1 -1
- data/spec/shoryuken/worker_spec.rb +15 -11
- data/spec/shoryuken_spec.rb +1 -1
- data/spec/spec_helper.rb +16 -0
- metadata +60 -27
- data/.github/FUNDING.yml +0 -12
- data/gemfiles/rails_6_1.gemfile +0 -18
- data/lib/shoryuken/core_ext.rb +0 -69
- data/lib/shoryuken/polling/base.rb +0 -67
- data/shoryuken.jpg +0 -0
- data/spec/shoryuken/core_ext_spec.rb +0 -40
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Shoryuken
|
|
4
|
+
module Polling
|
|
5
|
+
# Configuration object representing a queue and its associated options.
|
|
6
|
+
#
|
|
7
|
+
# This class encapsulates a queue name along with any polling-specific
|
|
8
|
+
# options or metadata. It provides a structured way to pass queue
|
|
9
|
+
# information between polling strategies and the message fetching system.
|
|
10
|
+
#
|
|
11
|
+
# The class extends Struct to provide attribute accessors for name and options
|
|
12
|
+
# while adding custom behavior for equality comparison and string representation.
|
|
13
|
+
#
|
|
14
|
+
# @example Creating a basic queue configuration
|
|
15
|
+
# config = QueueConfiguration.new('my_queue', {})
|
|
16
|
+
# config.name # => 'my_queue'
|
|
17
|
+
# config.options # => {}
|
|
18
|
+
#
|
|
19
|
+
# @example Creating a queue configuration with options
|
|
20
|
+
# config = QueueConfiguration.new('priority_queue', { priority: :high })
|
|
21
|
+
# config.name # => 'priority_queue'
|
|
22
|
+
# config.options # => { priority: :high }
|
|
23
|
+
#
|
|
24
|
+
# @example Comparing configurations
|
|
25
|
+
# config1 = QueueConfiguration.new('queue', {})
|
|
26
|
+
# config2 = QueueConfiguration.new('queue', {})
|
|
27
|
+
# config1 == config2 # => true
|
|
28
|
+
# config1 == 'queue' # => true (when options are empty)
|
|
29
|
+
#
|
|
30
|
+
# @attr_reader [String] name The name of the queue
|
|
31
|
+
# @attr_reader [Hash] options Additional options or metadata for the queue
|
|
32
|
+
QueueConfiguration = Struct.new(:name, :options) do
|
|
33
|
+
# Generates a hash value based on the queue name.
|
|
34
|
+
#
|
|
35
|
+
# This method ensures that QueueConfiguration objects can be used
|
|
36
|
+
# as hash keys and that configurations with the same queue name
|
|
37
|
+
# will have the same hash value regardless of their options.
|
|
38
|
+
#
|
|
39
|
+
# @return [Integer] Hash value based on the queue name
|
|
40
|
+
def hash
|
|
41
|
+
name.hash
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Compares this configuration with another object for equality.
|
|
45
|
+
#
|
|
46
|
+
# Two QueueConfiguration objects are equal if they have the same name
|
|
47
|
+
# and options. For convenience, a configuration with empty options can
|
|
48
|
+
# also be compared directly with a string queue name.
|
|
49
|
+
#
|
|
50
|
+
# @param other [Object] The object to compare with
|
|
51
|
+
# @return [Boolean] true if the objects are considered equal
|
|
52
|
+
#
|
|
53
|
+
# @example Comparing with another QueueConfiguration
|
|
54
|
+
# config1 = QueueConfiguration.new('queue', {})
|
|
55
|
+
# config2 = QueueConfiguration.new('queue', {})
|
|
56
|
+
# config1 == config2 # => true
|
|
57
|
+
#
|
|
58
|
+
# @example Comparing with a string (only when options are empty)
|
|
59
|
+
# config = QueueConfiguration.new('queue', {})
|
|
60
|
+
# config == 'queue' # => true
|
|
61
|
+
#
|
|
62
|
+
# config_with_options = QueueConfiguration.new('queue', { weight: 5 })
|
|
63
|
+
# config_with_options == 'queue' # => false
|
|
64
|
+
def ==(other)
|
|
65
|
+
case other
|
|
66
|
+
when String
|
|
67
|
+
if options.empty?
|
|
68
|
+
name == other
|
|
69
|
+
else
|
|
70
|
+
false
|
|
71
|
+
end
|
|
72
|
+
else
|
|
73
|
+
super
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
alias_method :eql?, :==
|
|
78
|
+
|
|
79
|
+
# Returns a string representation of the queue configuration.
|
|
80
|
+
#
|
|
81
|
+
# For configurations with empty options, returns just the queue name.
|
|
82
|
+
# For configurations with options, returns a detailed representation
|
|
83
|
+
# showing both the name and the options hash.
|
|
84
|
+
#
|
|
85
|
+
# @return [String] String representation of the configuration
|
|
86
|
+
#
|
|
87
|
+
# @example Simple queue without options
|
|
88
|
+
# config = QueueConfiguration.new('simple_queue', {})
|
|
89
|
+
# config.to_s # => 'simple_queue'
|
|
90
|
+
#
|
|
91
|
+
# @example Queue with options
|
|
92
|
+
# config = QueueConfiguration.new('complex_queue', { priority: :high })
|
|
93
|
+
# config.to_s # => '#<QueueConfiguration complex_queue options={:priority=>:high}>'
|
|
94
|
+
def to_s
|
|
95
|
+
if options&.empty?
|
|
96
|
+
name
|
|
97
|
+
else
|
|
98
|
+
"#<QueueConfiguration #{name} options=#{options.inspect}>"
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
data/lib/shoryuken/processor.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Shoryuken
|
|
2
4
|
class Processor
|
|
3
5
|
include Util
|
|
@@ -16,6 +18,7 @@ module Shoryuken
|
|
|
16
18
|
def process
|
|
17
19
|
worker_perform = proc do
|
|
18
20
|
return logger.error { "No worker found for #{queue}" } unless worker
|
|
21
|
+
|
|
19
22
|
Shoryuken::Logging.with_context("#{worker_name(worker.class, sqs_msg, body)}/#{queue}/#{sqs_msg.message_id}") do
|
|
20
23
|
worker.class.server_middleware.invoke(worker, queue, sqs_msg, body) do
|
|
21
24
|
worker.perform(sqs_msg, body)
|
|
@@ -30,8 +33,8 @@ module Shoryuken
|
|
|
30
33
|
else
|
|
31
34
|
worker_perform.call
|
|
32
35
|
end
|
|
33
|
-
rescue Exception =>
|
|
34
|
-
Array(Shoryuken.exception_handlers).each { |handler| handler.call(
|
|
36
|
+
rescue Exception => e
|
|
37
|
+
Array(Shoryuken.exception_handlers).each { |handler| handler.call(e, queue, sqs_msg) }
|
|
35
38
|
|
|
36
39
|
raise
|
|
37
40
|
end
|
data/lib/shoryuken/queue.rb
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Shoryuken
|
|
2
4
|
class Queue
|
|
3
5
|
include Util
|
|
4
6
|
|
|
5
|
-
FIFO_ATTR = 'FifoQueue'
|
|
6
|
-
MESSAGE_GROUP_ID = 'ShoryukenMessage'
|
|
7
|
-
VISIBILITY_TIMEOUT_ATTR = 'VisibilityTimeout'
|
|
7
|
+
FIFO_ATTR = 'FifoQueue'
|
|
8
|
+
MESSAGE_GROUP_ID = 'ShoryukenMessage'
|
|
9
|
+
VISIBILITY_TIMEOUT_ATTR = 'VisibilityTimeout'
|
|
8
10
|
|
|
9
11
|
attr_accessor :name, :client, :url
|
|
10
12
|
|
|
@@ -50,7 +52,7 @@ module Shoryuken
|
|
|
50
52
|
|
|
51
53
|
def fifo?
|
|
52
54
|
# Make sure the memoization work with boolean to avoid multiple calls to SQS
|
|
53
|
-
# see https://github.com/
|
|
55
|
+
# see https://github.com/ruby-shoryuken/shoryuken/pull/529
|
|
54
56
|
return @_fifo if defined?(@_fifo)
|
|
55
57
|
|
|
56
58
|
@_fifo = queue_attributes.attributes[FIFO_ATTR] == 'true'
|
data/lib/shoryuken/runner.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
$stdout.sync = true
|
|
2
4
|
|
|
3
5
|
require 'singleton'
|
|
@@ -7,7 +9,6 @@ require 'erb'
|
|
|
7
9
|
require 'shoryuken'
|
|
8
10
|
|
|
9
11
|
module Shoryuken
|
|
10
|
-
# rubocop:disable Lint/InheritException
|
|
11
12
|
# See: https://github.com/mperham/sidekiq/blob/33f5d6b2b6c0dfaab11e5d39688cab7ebadc83ae/lib/sidekiq/cli.rb#L20
|
|
12
13
|
class Shutdown < Interrupt; end
|
|
13
14
|
|
|
@@ -19,13 +20,11 @@ module Shoryuken
|
|
|
19
20
|
self_read, self_write = IO.pipe
|
|
20
21
|
|
|
21
22
|
%w[INT TERM USR1 TSTP TTIN].each do |sig|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
self_write.puts(sig)
|
|
25
|
-
end
|
|
26
|
-
rescue ArgumentError
|
|
27
|
-
puts "Signal #{sig} not supported"
|
|
23
|
+
trap sig do
|
|
24
|
+
self_write.puts(sig)
|
|
28
25
|
end
|
|
26
|
+
rescue ArgumentError
|
|
27
|
+
puts "Signal #{sig} not supported"
|
|
29
28
|
end
|
|
30
29
|
|
|
31
30
|
loader = EnvironmentLoader.setup_options(options)
|
|
@@ -77,11 +76,9 @@ module Shoryuken
|
|
|
77
76
|
Process.daemon(true, true)
|
|
78
77
|
|
|
79
78
|
files_to_reopen.each do |file|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
rescue ::Exception
|
|
84
|
-
end
|
|
79
|
+
file.reopen file.path, 'a+'
|
|
80
|
+
file.sync = true
|
|
81
|
+
rescue ::Exception
|
|
85
82
|
end
|
|
86
83
|
|
|
87
84
|
[$stdout, $stderr].each do |io|
|
data/lib/shoryuken/util.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Shoryuken
|
|
2
4
|
module Util
|
|
3
5
|
def logger
|
|
@@ -9,12 +11,10 @@ module Shoryuken
|
|
|
9
11
|
arr = Shoryuken.options[:lifecycle_events][event]
|
|
10
12
|
arr.reverse! if reverse
|
|
11
13
|
arr.each do |block|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
logger.warn "#{ex.class.name}: #{ex.message}"
|
|
17
|
-
end
|
|
14
|
+
block.call(event_options)
|
|
15
|
+
rescue => e
|
|
16
|
+
logger.warn(event: event)
|
|
17
|
+
logger.warn "#{e.class.name}: #{e.message}"
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
data/lib/shoryuken/version.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Shoryuken
|
|
2
4
|
module Worker
|
|
3
5
|
class InlineExecutor
|
|
@@ -11,7 +13,7 @@ module Shoryuken
|
|
|
11
13
|
data_type: 'String'
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
sqs_msg =
|
|
16
|
+
sqs_msg = InlineMessage.new(
|
|
15
17
|
body: body,
|
|
16
18
|
attributes: nil,
|
|
17
19
|
md5_of_body: nil,
|
data/lib/shoryuken/worker.rb
CHANGED
data/lib/shoryuken.rb
CHANGED
|
@@ -1,38 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'yaml'
|
|
2
4
|
require 'json'
|
|
3
5
|
require 'aws-sdk-sqs'
|
|
4
6
|
require 'time'
|
|
5
7
|
require 'concurrent'
|
|
6
8
|
require 'forwardable'
|
|
9
|
+
require 'zeitwerk'
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
require 'shoryuken/environment_loader'
|
|
13
|
-
require 'shoryuken/queue'
|
|
14
|
-
require 'shoryuken/message'
|
|
15
|
-
require 'shoryuken/client'
|
|
16
|
-
require 'shoryuken/worker'
|
|
17
|
-
require 'shoryuken/worker/default_executor'
|
|
18
|
-
require 'shoryuken/worker/inline_executor'
|
|
19
|
-
require 'shoryuken/worker_registry'
|
|
20
|
-
require 'shoryuken/default_worker_registry'
|
|
21
|
-
require 'shoryuken/default_exception_handler'
|
|
22
|
-
require 'shoryuken/middleware/chain'
|
|
23
|
-
require 'shoryuken/middleware/server/auto_delete'
|
|
24
|
-
Shoryuken::Middleware::Server.autoload :AutoExtendVisibility, 'shoryuken/middleware/server/auto_extend_visibility'
|
|
25
|
-
require 'shoryuken/middleware/server/exponential_backoff_retry'
|
|
26
|
-
require 'shoryuken/middleware/server/timing'
|
|
27
|
-
require 'shoryuken/polling/base'
|
|
28
|
-
require 'shoryuken/polling/weighted_round_robin'
|
|
29
|
-
require 'shoryuken/polling/strict_priority'
|
|
30
|
-
require 'shoryuken/manager'
|
|
31
|
-
require 'shoryuken/launcher'
|
|
32
|
-
require 'shoryuken/processor'
|
|
33
|
-
require 'shoryuken/body_parser'
|
|
34
|
-
require 'shoryuken/fetcher'
|
|
35
|
-
require 'shoryuken/options'
|
|
11
|
+
# Set up Zeitwerk loader
|
|
12
|
+
loader = Zeitwerk::Loader.for_gem
|
|
13
|
+
loader.ignore("#{__dir__}/shoryuken/extensions")
|
|
14
|
+
loader.setup
|
|
36
15
|
|
|
37
16
|
module Shoryuken
|
|
38
17
|
extend SingleForwardable
|
|
@@ -75,6 +54,7 @@ module Shoryuken
|
|
|
75
54
|
:exception_handlers=,
|
|
76
55
|
:options,
|
|
77
56
|
:logger,
|
|
57
|
+
:logger=,
|
|
78
58
|
:register_worker,
|
|
79
59
|
:configure_server,
|
|
80
60
|
:server?,
|
data/shoryuken.gemspec
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
lib = File.expand_path('lib', __dir__)
|
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
3
|
require 'shoryuken/version'
|
|
@@ -17,14 +16,15 @@ Gem::Specification.new do |spec|
|
|
|
17
16
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
18
17
|
spec.require_paths = ['lib']
|
|
19
18
|
|
|
19
|
+
spec.add_dependency 'aws-sdk-sqs', '>= 1.66.0'
|
|
20
|
+
spec.add_dependency 'concurrent-ruby'
|
|
21
|
+
spec.add_dependency 'thor'
|
|
22
|
+
spec.add_dependency 'zeitwerk', '~> 2.6'
|
|
23
|
+
|
|
20
24
|
spec.add_development_dependency 'dotenv'
|
|
21
25
|
spec.add_development_dependency 'ostruct'
|
|
22
26
|
spec.add_development_dependency 'rake'
|
|
23
27
|
spec.add_development_dependency 'rspec'
|
|
24
28
|
|
|
25
|
-
spec.
|
|
26
|
-
spec.add_dependency 'concurrent-ruby'
|
|
27
|
-
spec.add_dependency 'thor'
|
|
28
|
-
|
|
29
|
-
spec.required_ruby_version = '>= 3.0.0'
|
|
29
|
+
spec.required_ruby_version = '>= 3.1.0'
|
|
30
30
|
end
|
|
@@ -24,7 +24,7 @@ RSpec.shared_examples 'active_job_adapters' do
|
|
|
24
24
|
expect(queue).to receive(:send_message) do |hash|
|
|
25
25
|
expect(hash[:message_deduplication_id]).to_not be
|
|
26
26
|
expect(hash[:message_attributes]['shoryuken_class'][:string_value]).to eq(described_class::JobWrapper.to_s)
|
|
27
|
-
expect(hash[:message_attributes]['shoryuken_class'][:data_type]).to eq(
|
|
27
|
+
expect(hash[:message_attributes]['shoryuken_class'][:data_type]).to eq('String')
|
|
28
28
|
expect(hash[:message_attributes].keys).to eq(['shoryuken_class'])
|
|
29
29
|
end
|
|
30
30
|
expect(Shoryuken).to receive(:register_worker).with(job.queue_name, described_class::JobWrapper)
|
|
@@ -133,9 +133,9 @@ RSpec.shared_examples 'active_job_adapters' do
|
|
|
133
133
|
|
|
134
134
|
expect(queue).to receive(:send_message) do |hash|
|
|
135
135
|
expect(hash[:message_attributes]['shoryuken_class'][:string_value]).to eq(described_class::JobWrapper.to_s)
|
|
136
|
-
expect(hash[:message_attributes]['shoryuken_class'][:data_type]).to eq(
|
|
136
|
+
expect(hash[:message_attributes]['shoryuken_class'][:data_type]).to eq('String')
|
|
137
137
|
expect(hash[:message_attributes]['tracer_id'][:string_value]).to eq(custom_message_attributes['tracer_id'][:string_value])
|
|
138
|
-
expect(hash[:message_attributes]['tracer_id'][:data_type]).to eq(
|
|
138
|
+
expect(hash[:message_attributes]['tracer_id'][:data_type]).to eq('String')
|
|
139
139
|
end
|
|
140
140
|
expect(Shoryuken).to receive(:register_worker).with(job.queue_name, described_class::JobWrapper)
|
|
141
141
|
|
|
@@ -157,7 +157,8 @@ RSpec.shared_examples 'active_job_adapters' do
|
|
|
157
157
|
it 'should enqueue a message with the message_attributes specified on the job' do
|
|
158
158
|
expect(queue).to receive(:send_message) do |hash|
|
|
159
159
|
expect(hash[:message_attributes]['tracer_id']).to eq({ data_type: 'String', string_value: 'job-value' })
|
|
160
|
-
expect(hash[:message_attributes]['shoryuken_class']).to eq({ data_type: 'String',
|
|
160
|
+
expect(hash[:message_attributes]['shoryuken_class']).to eq({ data_type: 'String',
|
|
161
|
+
string_value: described_class::JobWrapper.to_s })
|
|
161
162
|
end
|
|
162
163
|
subject.enqueue job
|
|
163
164
|
end
|
|
@@ -185,8 +186,10 @@ RSpec.shared_examples 'active_job_adapters' do
|
|
|
185
186
|
|
|
186
187
|
expect(queue).to receive(:send_message) do |hash|
|
|
187
188
|
expect(hash[:message_attributes]['tracer_id']).to be_nil
|
|
188
|
-
expect(hash[:message_attributes]['options_tracer_id']).to eq({ data_type: 'String',
|
|
189
|
-
|
|
189
|
+
expect(hash[:message_attributes]['options_tracer_id']).to eq({ data_type: 'String',
|
|
190
|
+
string_value: 'options-value' })
|
|
191
|
+
expect(hash[:message_attributes]['shoryuken_class']).to eq({ data_type: 'String',
|
|
192
|
+
string_value: described_class::JobWrapper.to_s })
|
|
190
193
|
end
|
|
191
194
|
subject.enqueue job, message_attributes: custom_message_attributes
|
|
192
195
|
end
|
|
@@ -225,7 +228,8 @@ RSpec.shared_examples 'active_job_adapters' do
|
|
|
225
228
|
|
|
226
229
|
it 'should enqueue a message with the message_system_attributes specified on the job' do
|
|
227
230
|
expect(queue).to receive(:send_message) do |hash|
|
|
228
|
-
expect(hash[:message_system_attributes]['AWSTraceHeader']).to eq({ data_type: 'String',
|
|
231
|
+
expect(hash[:message_system_attributes]['AWSTraceHeader']).to eq({ data_type: 'String',
|
|
232
|
+
string_value: 'job-value' })
|
|
229
233
|
end
|
|
230
234
|
subject.enqueue job
|
|
231
235
|
end
|
|
@@ -253,7 +257,8 @@ RSpec.shared_examples 'active_job_adapters' do
|
|
|
253
257
|
|
|
254
258
|
expect(queue).to receive(:send_message) do |hash|
|
|
255
259
|
expect(hash[:message_system_attributes]['job_trace_header']).to be_nil
|
|
256
|
-
expect(hash[:message_system_attributes]['options_trace_header']).to eq({ data_type: 'String',
|
|
260
|
+
expect(hash[:message_system_attributes]['options_trace_header']).to eq({ data_type: 'String',
|
|
261
|
+
string_value: 'options-value' })
|
|
257
262
|
end
|
|
258
263
|
subject.enqueue job, message_system_attributes: custom_message_attributes
|
|
259
264
|
end
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# rubocop:disable Metrics/BlockLength
|
|
4
3
|
RSpec.describe Shoryuken::DefaultExceptionHandler do
|
|
5
4
|
class CustomErrorHandler
|
|
6
5
|
extend Shoryuken::Util
|
|
7
6
|
|
|
8
7
|
def self.call(_ex, queue, _msg)
|
|
9
|
-
logger.error("#{queue
|
|
8
|
+
logger.error("#{queue} failed to process the message")
|
|
10
9
|
end
|
|
11
10
|
end
|
|
12
11
|
|
|
@@ -38,31 +37,31 @@ RSpec.describe Shoryuken::DefaultExceptionHandler do
|
|
|
38
37
|
|
|
39
38
|
subject { Shoryuken::Processor.new(queue, sqs_msg) }
|
|
40
39
|
|
|
41
|
-
context
|
|
40
|
+
context 'with default handler' do
|
|
42
41
|
before do
|
|
43
42
|
Shoryuken.exception_handlers = described_class
|
|
44
43
|
end
|
|
45
44
|
|
|
46
|
-
it
|
|
45
|
+
it 'logs an error message' do
|
|
47
46
|
expect(Shoryuken::Logging.logger).to receive(:error).twice
|
|
48
47
|
|
|
49
|
-
allow_any_instance_of(TestWorker).to receive(:perform).and_raise(StandardError,
|
|
48
|
+
allow_any_instance_of(TestWorker).to receive(:perform).and_raise(StandardError, 'error')
|
|
50
49
|
allow(sqs_msg).to receive(:body)
|
|
51
50
|
|
|
52
51
|
expect { subject.process }.to raise_error(StandardError)
|
|
53
52
|
end
|
|
54
53
|
end
|
|
55
54
|
|
|
56
|
-
context
|
|
55
|
+
context 'with custom handler' do
|
|
57
56
|
before do
|
|
58
57
|
Shoryuken.exception_handlers = [described_class, CustomErrorHandler]
|
|
59
58
|
end
|
|
60
59
|
|
|
61
|
-
it
|
|
60
|
+
it 'logs default and custom error messages' do
|
|
62
61
|
expect(Shoryuken::Logging.logger).to receive(:error).twice
|
|
63
|
-
expect(Shoryuken::Logging.logger).to receive(:error).with(
|
|
62
|
+
expect(Shoryuken::Logging.logger).to receive(:error).with('default failed to process the message').once
|
|
64
63
|
|
|
65
|
-
allow_any_instance_of(TestWorker).to receive(:perform).and_raise(StandardError,
|
|
64
|
+
allow_any_instance_of(TestWorker).to receive(:perform).and_raise(StandardError, 'error')
|
|
66
65
|
allow(sqs_msg).to receive(:body)
|
|
67
66
|
|
|
68
67
|
expect { subject.process }.to raise_error(StandardError)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
require 'active_job'
|
|
3
4
|
|
|
4
5
|
RSpec.describe Shoryuken::EnvironmentLoader do
|
|
@@ -63,7 +64,7 @@ RSpec.describe Shoryuken::EnvironmentLoader do
|
|
|
63
64
|
end
|
|
64
65
|
|
|
65
66
|
specify do
|
|
66
|
-
Shoryuken.options[:queues] = [
|
|
67
|
+
Shoryuken.options[:queues] = %w[queue1 queue2] # default queues
|
|
67
68
|
Shoryuken.options[:groups] = [['custom', { queues: ['queue3'], delay: 25 }]]
|
|
68
69
|
subject.load
|
|
69
70
|
|
|
@@ -124,11 +125,11 @@ RSpec.describe Shoryuken::EnvironmentLoader do
|
|
|
124
125
|
end
|
|
125
126
|
end
|
|
126
127
|
|
|
127
|
-
describe
|
|
128
|
-
let(:cli_queues) { {
|
|
129
|
-
let(:config_queues) { [[
|
|
128
|
+
describe '#setup_options' do
|
|
129
|
+
let(:cli_queues) { { 'queue1' => 10, 'queue2' => 20 } }
|
|
130
|
+
let(:config_queues) { [['queue1', 8], ['queue2', 4]] }
|
|
130
131
|
|
|
131
|
-
context
|
|
132
|
+
context 'when given queues through config and CLI' do
|
|
132
133
|
specify do
|
|
133
134
|
allow_any_instance_of(Shoryuken::EnvironmentLoader).to receive(:config_file_options).and_return({ queues: config_queues })
|
|
134
135
|
Shoryuken::EnvironmentLoader.setup_options(queues: cli_queues)
|
|
@@ -136,7 +137,7 @@ RSpec.describe Shoryuken::EnvironmentLoader do
|
|
|
136
137
|
end
|
|
137
138
|
end
|
|
138
139
|
|
|
139
|
-
context
|
|
140
|
+
context 'when given queues through config only' do
|
|
140
141
|
specify do
|
|
141
142
|
allow_any_instance_of(Shoryuken::EnvironmentLoader).to receive(:config_file_options).and_return({ queues: config_queues })
|
|
142
143
|
Shoryuken::EnvironmentLoader.setup_options({})
|
|
@@ -144,7 +145,7 @@ RSpec.describe Shoryuken::EnvironmentLoader do
|
|
|
144
145
|
end
|
|
145
146
|
end
|
|
146
147
|
|
|
147
|
-
context
|
|
148
|
+
context 'when given queues through CLI only' do
|
|
148
149
|
specify do
|
|
149
150
|
Shoryuken::EnvironmentLoader.setup_options(queues: cli_queues)
|
|
150
151
|
expect(Shoryuken.options[:queues]).to eq(cli_queues)
|