shoryuken 7.0.0.alpha2 → 7.0.0
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 +2 -2
- data/.github/workflows/specs.yml +38 -43
- data/.github/workflows/verify-action-pins.yml +1 -1
- data/.gitignore +3 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -1
- data/.yard-lint.yml +279 -0
- data/CHANGELOG.md +69 -1
- data/Gemfile +1 -1
- data/README.md +2 -7
- data/Rakefile +4 -10
- data/bin/clean_localstack +52 -0
- data/bin/cli/base.rb +21 -0
- data/bin/cli/sqs.rb +61 -2
- data/bin/integrations +275 -0
- data/bin/scenario +154 -0
- data/bin/shoryuken +1 -1
- data/lib/{shoryuken/extensions/active_job_extensions.rb → active_job/extensions.rb} +15 -4
- data/lib/active_job/queue_adapters/shoryuken_adapter.rb +208 -0
- data/lib/active_job/queue_adapters/shoryuken_concurrent_send_adapter.rb +78 -0
- data/lib/shoryuken/active_job/current_attributes.rb +139 -0
- data/lib/shoryuken/active_job/job_wrapper.rb +28 -0
- data/lib/shoryuken/body_parser.rb +8 -0
- data/lib/shoryuken/client.rb +14 -0
- data/lib/shoryuken/default_exception_handler.rb +9 -0
- data/lib/shoryuken/default_worker_registry.rb +29 -1
- data/lib/shoryuken/environment_loader.rb +78 -8
- data/lib/shoryuken/errors.rb +33 -0
- data/lib/shoryuken/fetcher.rb +37 -1
- data/lib/shoryuken/helpers/atomic_boolean.rb +19 -5
- data/lib/shoryuken/helpers/timer_task.rb +80 -0
- data/lib/shoryuken/launcher.rb +53 -0
- data/lib/shoryuken/logging/base.rb +26 -0
- data/lib/shoryuken/logging/pretty.rb +25 -0
- data/lib/shoryuken/logging/without_timestamp.rb +25 -0
- data/lib/shoryuken/logging.rb +39 -25
- data/lib/shoryuken/manager.rb +70 -1
- data/lib/shoryuken/message.rb +114 -1
- data/lib/shoryuken/middleware/chain.rb +139 -43
- data/lib/shoryuken/middleware/entry.rb +30 -0
- data/lib/shoryuken/middleware/server/active_record.rb +8 -0
- data/lib/shoryuken/middleware/server/auto_delete.rb +10 -0
- data/lib/shoryuken/middleware/server/auto_extend_visibility.rb +27 -1
- data/lib/shoryuken/middleware/server/exponential_backoff_retry.rb +29 -0
- data/lib/shoryuken/middleware/server/timing.rb +11 -0
- data/lib/shoryuken/options.rb +129 -6
- data/lib/shoryuken/polling/base_strategy.rb +1 -0
- data/lib/shoryuken/polling/strict_priority.rb +39 -0
- data/lib/shoryuken/polling/weighted_round_robin.rb +42 -0
- data/lib/shoryuken/processor.rb +32 -1
- data/lib/shoryuken/queue.rb +93 -4
- data/lib/shoryuken/runner.rb +45 -4
- data/lib/shoryuken/util.rb +26 -1
- data/lib/shoryuken/version.rb +2 -1
- data/lib/shoryuken/worker/default_executor.rb +21 -1
- data/lib/shoryuken/worker/inline_executor.rb +24 -0
- data/lib/shoryuken/worker.rb +193 -0
- data/lib/shoryuken/worker_registry.rb +33 -0
- data/lib/shoryuken.rb +18 -6
- data/renovate.json +29 -2
- data/shoryuken.gemspec +2 -1
- data/spec/integration/.rspec +1 -0
- data/spec/integration/active_job/adapter_configuration/configuration_spec.rb +26 -0
- data/spec/integration/active_job/bulk_enqueue/bulk_enqueue_spec.rb +53 -0
- data/spec/integration/active_job/current_attributes/bulk_enqueue_spec.rb +50 -0
- data/spec/integration/active_job/current_attributes/complex_types_spec.rb +55 -0
- data/spec/integration/active_job/current_attributes/empty_context_spec.rb +41 -0
- data/spec/integration/active_job/current_attributes/full_context_spec.rb +63 -0
- data/spec/integration/active_job/current_attributes/partial_context_spec.rb +57 -0
- data/spec/integration/active_job/custom_attributes/number_attributes_spec.rb +37 -0
- data/spec/integration/active_job/custom_attributes/string_attributes_spec.rb +39 -0
- data/spec/integration/active_job/error_handling/job_wrapper_spec.rb +53 -0
- data/spec/integration/active_job/fifo_and_attributes/deduplication_spec.rb +86 -0
- data/spec/integration/active_job/retry/discard_on_spec.rb +43 -0
- data/spec/integration/active_job/retry/retry_on_spec.rb +36 -0
- data/spec/integration/active_job/roundtrip/roundtrip_spec.rb +52 -0
- data/spec/integration/active_job/scheduled/scheduled_spec.rb +76 -0
- data/spec/integration/active_record_middleware/active_record_middleware_spec.rb +84 -0
- data/spec/integration/auto_delete/auto_delete_spec.rb +53 -0
- data/spec/integration/auto_extend_visibility/auto_extend_visibility_spec.rb +57 -0
- data/spec/integration/aws_config/aws_config_spec.rb +59 -0
- data/spec/integration/batch_processing/batch_processing_spec.rb +37 -0
- data/spec/integration/body_parser/json_parser_spec.rb +45 -0
- data/spec/integration/body_parser/proc_parser_spec.rb +54 -0
- data/spec/integration/body_parser/text_parser_spec.rb +43 -0
- data/spec/integration/concurrent_processing/concurrent_processing_spec.rb +45 -0
- data/spec/integration/dead_letter_queue/dead_letter_queue_spec.rb +91 -0
- data/spec/integration/exception_handlers/exception_handlers_spec.rb +69 -0
- data/spec/integration/exponential_backoff/exponential_backoff_spec.rb +67 -0
- data/spec/integration/fifo_ordering/fifo_ordering_spec.rb +44 -0
- data/spec/integration/large_payloads/large_payloads_spec.rb +30 -0
- data/spec/integration/launcher/launcher_spec.rb +40 -0
- data/spec/integration/message_attributes/message_attributes_spec.rb +54 -0
- data/spec/integration/message_operations/message_operations_spec.rb +59 -0
- data/spec/integration/middleware_chain/empty_chain_spec.rb +11 -0
- data/spec/integration/middleware_chain/execution_order_spec.rb +33 -0
- data/spec/integration/middleware_chain/removal_spec.rb +31 -0
- data/spec/integration/middleware_chain/short_circuit_spec.rb +40 -0
- data/spec/integration/polling_strategies/polling_strategies_spec.rb +46 -0
- data/spec/integration/queue_operations/queue_operations_spec.rb +84 -0
- data/spec/integration/rails/rails_72/Gemfile +6 -0
- data/spec/integration/rails/rails_72/activejob_adapter_spec.rb +98 -0
- data/spec/integration/rails/rails_80/Gemfile +6 -0
- data/spec/integration/rails/rails_80/activejob_adapter_spec.rb +98 -0
- data/spec/integration/rails/rails_80/continuation_spec.rb +79 -0
- data/spec/integration/rails/rails_81/Gemfile +6 -0
- data/spec/integration/rails/rails_81/activejob_adapter_spec.rb +98 -0
- data/spec/integration/rails/rails_81/continuation_spec.rb +79 -0
- data/spec/integration/retry_behavior/retry_behavior_spec.rb +45 -0
- data/spec/integration/spec_helper.rb +7 -0
- data/spec/integration/strict_priority_polling/strict_priority_polling_spec.rb +58 -0
- data/spec/integration/visibility_timeout/visibility_timeout_spec.rb +37 -0
- data/spec/integration/worker_enqueueing/worker_enqueueing_spec.rb +60 -0
- data/spec/integration/worker_groups/worker_groups_spec.rb +79 -0
- data/spec/integration/worker_lifecycle/worker_lifecycle_spec.rb +33 -0
- data/spec/integrations_helper.rb +243 -0
- data/spec/lib/active_job/extensions_spec.rb +149 -0
- data/spec/lib/active_job/queue_adapters/shoryuken_adapter_spec.rb +29 -0
- data/spec/{shoryuken/extensions/active_job_concurrent_send_adapter_spec.rb → lib/active_job/queue_adapters/shoryuken_concurrent_send_adapter_spec.rb} +3 -3
- data/spec/{shoryuken/extensions/active_job_wrapper_spec.rb → lib/shoryuken/active_job/job_wrapper_spec.rb} +4 -4
- data/spec/{shoryuken → lib/shoryuken}/environment_loader_spec.rb +1 -1
- data/spec/{shoryuken → lib/shoryuken}/helpers/hash_utils_spec.rb +14 -14
- data/spec/{shoryuken → lib/shoryuken}/helpers/string_utils_spec.rb +3 -3
- data/spec/lib/shoryuken/helpers/timer_task_spec.rb +298 -0
- data/spec/{shoryuken → lib/shoryuken}/helpers_integration_spec.rb +9 -9
- data/spec/{shoryuken → lib/shoryuken}/launcher_spec.rb +22 -0
- data/spec/lib/shoryuken/logging_spec.rb +242 -0
- data/spec/lib/shoryuken/message_spec.rb +109 -0
- data/spec/lib/shoryuken/middleware/entry_spec.rb +68 -0
- data/spec/lib/shoryuken/middleware/server/active_record_spec.rb +133 -0
- data/spec/{shoryuken → lib/shoryuken}/middleware/server/auto_extend_visibility_spec.rb +50 -0
- data/spec/{shoryuken → lib/shoryuken}/options_spec.rb +2 -2
- data/spec/{shoryuken → lib/shoryuken}/util_spec.rb +1 -1
- data/spec/lib/shoryuken/version_spec.rb +17 -0
- data/spec/lib/shoryuken/worker_registry_spec.rb +63 -0
- data/spec/shared_examples_for_active_job.rb +29 -9
- data/spec/spec_helper.rb +34 -3
- metadata +230 -91
- data/.devcontainer/Dockerfile +0 -17
- data/.devcontainer/base.Dockerfile +0 -43
- data/.devcontainer/devcontainer.json +0 -35
- data/Appraisals +0 -23
- data/gemfiles/.gitignore +0 -1
- data/gemfiles/rails_7_0.gemfile +0 -19
- data/gemfiles/rails_7_1.gemfile +0 -19
- data/gemfiles/rails_7_2.gemfile +0 -19
- data/gemfiles/rails_8_0.gemfile +0 -19
- data/lib/shoryuken/extensions/active_job_adapter.rb +0 -110
- data/lib/shoryuken/extensions/active_job_concurrent_send_adapter.rb +0 -50
- data/spec/integration/launcher_spec.rb +0 -127
- data/spec/shoryuken/extensions/active_job_adapter_spec.rb +0 -8
- data/spec/shoryuken/extensions/active_job_base_spec.rb +0 -85
- /data/spec/{shoryuken → lib/shoryuken}/body_parser_spec.rb +0 -0
- /data/spec/{shoryuken → lib/shoryuken}/client_spec.rb +0 -0
- /data/spec/{shoryuken → lib/shoryuken}/default_exception_handler_spec.rb +0 -0
- /data/spec/{shoryuken → lib/shoryuken}/default_worker_registry_spec.rb +0 -0
- /data/spec/{shoryuken → lib/shoryuken}/fetcher_spec.rb +0 -0
- /data/spec/{shoryuken → lib/shoryuken}/helpers/atomic_boolean_spec.rb +0 -0
- /data/spec/{shoryuken → lib/shoryuken}/helpers/atomic_counter_spec.rb +0 -0
- /data/spec/{shoryuken → lib/shoryuken}/helpers/atomic_hash_spec.rb +0 -0
- /data/spec/{shoryuken → lib/shoryuken}/inline_message_spec.rb +0 -0
- /data/spec/{shoryuken → lib/shoryuken}/manager_spec.rb +0 -0
- /data/spec/{shoryuken → lib/shoryuken}/middleware/chain_spec.rb +0 -0
- /data/spec/{shoryuken → lib/shoryuken}/middleware/server/auto_delete_spec.rb +0 -0
- /data/spec/{shoryuken → lib/shoryuken}/middleware/server/exponential_backoff_retry_spec.rb +0 -0
- /data/spec/{shoryuken → lib/shoryuken}/middleware/server/timing_spec.rb +0 -0
- /data/spec/{shoryuken → lib/shoryuken}/polling/base_strategy_spec.rb +0 -0
- /data/spec/{shoryuken → lib/shoryuken}/polling/queue_configuration_spec.rb +0 -0
- /data/spec/{shoryuken → lib/shoryuken}/polling/strict_priority_spec.rb +0 -0
- /data/spec/{shoryuken → lib/shoryuken}/polling/weighted_round_robin_spec.rb +0 -0
- /data/spec/{shoryuken → lib/shoryuken}/processor_spec.rb +0 -0
- /data/spec/{shoryuken → lib/shoryuken}/queue_spec.rb +0 -0
- /data/spec/{shoryuken → lib/shoryuken}/runner_spec.rb +0 -0
- /data/spec/{shoryuken → lib/shoryuken}/worker/default_executor_spec.rb +0 -0
- /data/spec/{shoryuken → lib/shoryuken}/worker/inline_executor_spec.rb +0 -0
- /data/spec/{shoryuken → lib/shoryuken}/worker_spec.rb +0 -0
- /data/spec/{shoryuken_spec.rb → lib/shoryuken_spec.rb} +0 -0
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# ActiveJob docs: http://edgeguides.rubyonrails.org/active_job_basics.html
|
|
4
|
-
# Example adapters ref: https://github.com/rails/rails/tree/master/activejob/lib/active_job/queue_adapters
|
|
5
|
-
|
|
6
|
-
require 'shoryuken'
|
|
7
|
-
|
|
8
|
-
module ActiveJob
|
|
9
|
-
module QueueAdapters
|
|
10
|
-
# == Shoryuken adapter for Active Job
|
|
11
|
-
#
|
|
12
|
-
# Shoryuken ("sho-ryu-ken") is a super-efficient AWS SQS thread based message processor.
|
|
13
|
-
#
|
|
14
|
-
# Read more about Shoryuken {here}[https://github.com/ruby-shoryuken/shoryuken].
|
|
15
|
-
#
|
|
16
|
-
# To use Shoryuken set the queue_adapter config to +:shoryuken+.
|
|
17
|
-
#
|
|
18
|
-
# Rails.application.config.active_job.queue_adapter = :shoryuken
|
|
19
|
-
class ShoryukenAdapter < ActiveJob::QueueAdapters::AbstractAdapter
|
|
20
|
-
class << self
|
|
21
|
-
def instance
|
|
22
|
-
# https://github.com/ruby-shoryuken/shoryuken/pull/174#issuecomment-174555657
|
|
23
|
-
@instance ||= new
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def enqueue(job)
|
|
27
|
-
instance.enqueue(job)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def enqueue_at(job, timestamp)
|
|
31
|
-
instance.enqueue_at(job, timestamp)
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
# only required for Rails 7.2.x
|
|
36
|
-
def enqueue_after_transaction_commit?
|
|
37
|
-
true
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def enqueue(job, options = {}) # :nodoc:
|
|
41
|
-
register_worker!(job)
|
|
42
|
-
|
|
43
|
-
job.sqs_send_message_parameters.merge! options
|
|
44
|
-
|
|
45
|
-
queue = Shoryuken::Client.queues(job.queue_name)
|
|
46
|
-
send_message_params = message queue, job
|
|
47
|
-
job.sqs_send_message_parameters = send_message_params
|
|
48
|
-
queue.send_message send_message_params
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def enqueue_at(job, timestamp) # :nodoc:
|
|
52
|
-
enqueue(job, delay_seconds: calculate_delay(timestamp))
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
private
|
|
56
|
-
|
|
57
|
-
def calculate_delay(timestamp)
|
|
58
|
-
delay = (timestamp - Time.current.to_f).round
|
|
59
|
-
raise 'The maximum allowed delay is 15 minutes' if delay > 15.minutes
|
|
60
|
-
|
|
61
|
-
delay
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def message(queue, job)
|
|
65
|
-
body = job.serialize
|
|
66
|
-
job_params = job.sqs_send_message_parameters
|
|
67
|
-
|
|
68
|
-
attributes = job_params[:message_attributes] || {}
|
|
69
|
-
|
|
70
|
-
msg = {
|
|
71
|
-
message_body: body,
|
|
72
|
-
message_attributes: attributes.merge(MESSAGE_ATTRIBUTES)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if queue.fifo?
|
|
76
|
-
# See https://github.com/ruby-shoryuken/shoryuken/issues/457 and
|
|
77
|
-
# https://github.com/ruby-shoryuken/shoryuken/pull/750#issuecomment-1781317929
|
|
78
|
-
msg[:message_deduplication_id] = Digest::SHA256.hexdigest(
|
|
79
|
-
JSON.dump(body.except('job_id', 'enqueued_at'))
|
|
80
|
-
)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
msg.merge(job_params.except(:message_attributes))
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def register_worker!(job)
|
|
87
|
-
Shoryuken.register_worker(job.queue_name, JobWrapper)
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
class JobWrapper # :nodoc:
|
|
91
|
-
include Shoryuken::Worker
|
|
92
|
-
|
|
93
|
-
shoryuken_options body_parser: :json, auto_delete: true
|
|
94
|
-
|
|
95
|
-
def perform(sqs_msg, hash)
|
|
96
|
-
receive_count = sqs_msg.attributes['ApproximateReceiveCount'].to_i
|
|
97
|
-
past_receives = receive_count - 1
|
|
98
|
-
Base.execute hash.merge({ 'executions' => past_receives })
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
MESSAGE_ATTRIBUTES = {
|
|
103
|
-
'shoryuken_class' => {
|
|
104
|
-
string_value: JobWrapper.to_s,
|
|
105
|
-
data_type: 'String'
|
|
106
|
-
}
|
|
107
|
-
}.freeze
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
end
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# ActiveJob docs: http://edgeguides.rubyonrails.org/active_job_basics.html
|
|
4
|
-
# Example adapters ref: https://github.com/rails/rails/tree/master/activejob/lib/active_job/queue_adapters
|
|
5
|
-
module ActiveJob
|
|
6
|
-
module QueueAdapters
|
|
7
|
-
# == Shoryuken concurrent adapter for Active Job
|
|
8
|
-
#
|
|
9
|
-
# This adapter sends messages asynchronously (ie non-blocking) and allows
|
|
10
|
-
# the caller to set up handlers for both success and failure
|
|
11
|
-
#
|
|
12
|
-
# To use this adapter, set up as:
|
|
13
|
-
#
|
|
14
|
-
# success_handler = ->(response, job, options) { StatsD.increment("#{job.class.name}.success") }
|
|
15
|
-
# error_handler = ->(err, job, options) { StatsD.increment("#{job.class.name}.failure") }
|
|
16
|
-
#
|
|
17
|
-
# adapter = ActiveJob::QueueAdapters::ShoryukenConcurrentSendAdapter.new(success_handler, error_handler)
|
|
18
|
-
#
|
|
19
|
-
# config.active_job.queue_adapter = adapter
|
|
20
|
-
class ShoryukenConcurrentSendAdapter < ShoryukenAdapter
|
|
21
|
-
def initialize(success_handler = nil, error_handler = nil)
|
|
22
|
-
@success_handler = success_handler
|
|
23
|
-
@error_handler = error_handler
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def enqueue(job, options = {})
|
|
27
|
-
send_concurrently(job, options) { |f_job, f_options| super(f_job, f_options) }
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def success_handler
|
|
31
|
-
@success_handler ||= ->(_send_message_response, _job, _options) { nil }
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def error_handler
|
|
35
|
-
@error_handler ||= lambda { |error, job, _options|
|
|
36
|
-
Shoryuken.logger.warn("Failed to enqueue job: #{job.inspect} due to error: #{error}")
|
|
37
|
-
}
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
private
|
|
41
|
-
|
|
42
|
-
def send_concurrently(job, options)
|
|
43
|
-
Concurrent::Promises
|
|
44
|
-
.future(job, options) { |f_job, f_options| [yield(f_job, f_options), f_job, f_options] }
|
|
45
|
-
.then { |send_message_response, f_job, f_options| success_handler.call(send_message_response, f_job, f_options) }
|
|
46
|
-
.rescue(job, options) { |err, f_job, f_options| error_handler.call(err, f_job, f_options) }
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'securerandom'
|
|
4
|
-
|
|
5
|
-
RSpec.describe Shoryuken::Launcher do
|
|
6
|
-
let(:sqs_client) do
|
|
7
|
-
Aws::SQS::Client.new(
|
|
8
|
-
region: 'us-east-1',
|
|
9
|
-
endpoint: 'http://localhost:4566',
|
|
10
|
-
access_key_id: 'fake',
|
|
11
|
-
secret_access_key: 'fake'
|
|
12
|
-
)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
let(:executor) do
|
|
16
|
-
# We can't use Concurrent.global_io_executor in these tests since once you
|
|
17
|
-
# shut down a thread pool, you can't start it back up. Instead, we create
|
|
18
|
-
# one new thread pool executor for each spec. We use a new
|
|
19
|
-
# CachedThreadPool, since that most closely resembles
|
|
20
|
-
# Concurrent.global_io_executor
|
|
21
|
-
Concurrent::CachedThreadPool.new auto_terminate: true
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
describe 'Consuming messages' do
|
|
25
|
-
before do
|
|
26
|
-
Aws.config[:stub_responses] = false
|
|
27
|
-
|
|
28
|
-
allow(Shoryuken).to receive(:launcher_executor).and_return(executor)
|
|
29
|
-
|
|
30
|
-
Shoryuken.configure_client do |config|
|
|
31
|
-
config.sqs_client = sqs_client
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
Shoryuken.configure_server do |config|
|
|
35
|
-
config.sqs_client = sqs_client
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
StandardWorker.received_messages = 0
|
|
39
|
-
|
|
40
|
-
queue = "shoryuken-travis-#{StandardWorker}-#{SecureRandom.uuid}"
|
|
41
|
-
|
|
42
|
-
Shoryuken::Client.sqs.create_queue(queue_name: queue)
|
|
43
|
-
|
|
44
|
-
Shoryuken.add_group('default', 1)
|
|
45
|
-
Shoryuken.add_queue(queue, 1, 'default')
|
|
46
|
-
|
|
47
|
-
StandardWorker.get_shoryuken_options['queue'] = queue
|
|
48
|
-
|
|
49
|
-
Shoryuken.register_worker(queue, StandardWorker)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
after do
|
|
53
|
-
Aws.config[:stub_responses] = true
|
|
54
|
-
|
|
55
|
-
queue_url = Shoryuken::Client.sqs.get_queue_url(
|
|
56
|
-
queue_name: StandardWorker.get_shoryuken_options['queue']
|
|
57
|
-
).queue_url
|
|
58
|
-
|
|
59
|
-
Shoryuken::Client.sqs.delete_queue(queue_url: queue_url)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
it 'consumes as a command worker' do
|
|
63
|
-
StandardWorker.perform_async('Yo')
|
|
64
|
-
|
|
65
|
-
poll_queues_until { StandardWorker.received_messages > 0 }
|
|
66
|
-
|
|
67
|
-
expect(StandardWorker.received_messages).to eq 1
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it 'consumes a message' do
|
|
71
|
-
StandardWorker.get_shoryuken_options['batch'] = false
|
|
72
|
-
|
|
73
|
-
Shoryuken::Client.queues(StandardWorker.get_shoryuken_options['queue']).send_message(message_body: 'Yo')
|
|
74
|
-
|
|
75
|
-
poll_queues_until { StandardWorker.received_messages > 0 }
|
|
76
|
-
|
|
77
|
-
expect(StandardWorker.received_messages).to eq 1
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
it 'consumes a batch' do
|
|
81
|
-
StandardWorker.get_shoryuken_options['batch'] = true
|
|
82
|
-
|
|
83
|
-
entries = 10.times.map { |i| { id: SecureRandom.uuid, message_body: i.to_s } }
|
|
84
|
-
|
|
85
|
-
Shoryuken::Client.queues(StandardWorker.get_shoryuken_options['queue']).send_messages(entries: entries)
|
|
86
|
-
|
|
87
|
-
# Give the messages a chance to hit the queue so they are all available at the same time
|
|
88
|
-
sleep 2
|
|
89
|
-
|
|
90
|
-
poll_queues_until { StandardWorker.received_messages > 0 }
|
|
91
|
-
|
|
92
|
-
expect(StandardWorker.received_messages).to be > 1
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def poll_queues_until
|
|
96
|
-
subject.start
|
|
97
|
-
|
|
98
|
-
Timeout::timeout(10) do
|
|
99
|
-
begin
|
|
100
|
-
sleep 0.5
|
|
101
|
-
end until yield
|
|
102
|
-
end
|
|
103
|
-
ensure
|
|
104
|
-
subject.stop
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
class StandardWorker
|
|
108
|
-
include Shoryuken::Worker
|
|
109
|
-
|
|
110
|
-
@@received_messages = 0
|
|
111
|
-
|
|
112
|
-
shoryuken_options auto_delete: true
|
|
113
|
-
|
|
114
|
-
def perform(sqs_msg, _body)
|
|
115
|
-
@@received_messages += Array(sqs_msg).size
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
def self.received_messages
|
|
119
|
-
@@received_messages
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
def self.received_messages=(received_messages)
|
|
123
|
-
@@received_messages = received_messages
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
end
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'active_job'
|
|
4
|
-
require 'shoryuken/extensions/active_job_extensions'
|
|
5
|
-
require 'shoryuken/extensions/active_job_adapter'
|
|
6
|
-
|
|
7
|
-
RSpec.describe ActiveJob::Base do
|
|
8
|
-
let(:queue_adapter) { ActiveJob::QueueAdapters::ShoryukenAdapter.new }
|
|
9
|
-
|
|
10
|
-
subject do
|
|
11
|
-
worker_class = Class.new(described_class)
|
|
12
|
-
Object.const_set :MyWorker, worker_class
|
|
13
|
-
worker_class.queue_adapter = queue_adapter
|
|
14
|
-
worker_class
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
after do
|
|
18
|
-
Object.send :remove_const, :MyWorker
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
describe '#perform_now' do
|
|
22
|
-
it 'allows keyword args' do
|
|
23
|
-
collaborator = double 'worker collaborator'
|
|
24
|
-
subject.send(:define_method, :perform) do |**kwargs|
|
|
25
|
-
collaborator.foo(**kwargs)
|
|
26
|
-
end
|
|
27
|
-
expect(collaborator).to receive(:foo).with(foo: 'bar')
|
|
28
|
-
subject.perform_now foo: 'bar'
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
describe '#perform_later' do
|
|
33
|
-
it 'calls enqueue on the adapter with the expected job' do
|
|
34
|
-
expect(queue_adapter).to receive(:enqueue) do |job|
|
|
35
|
-
expect(job.arguments).to eq([1, 2])
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
subject.perform_later 1, 2
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it 'passes message_group_id to the queue_adapter' do
|
|
42
|
-
expect(queue_adapter).to receive(:enqueue) do |job|
|
|
43
|
-
expect(job.sqs_send_message_parameters[:message_group_id]).to eq('group-2')
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
subject.set(message_group_id: 'group-2').perform_later 1, 2
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it 'passes message_deduplication_id to the queue_adapter' do
|
|
50
|
-
expect(queue_adapter).to receive(:enqueue) do |job|
|
|
51
|
-
expect(job.sqs_send_message_parameters[:message_deduplication_id]).to eq('dedupe-id')
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
subject.set(message_deduplication_id: 'dedupe-id').perform_later 1, 2
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
it 'passes message_attributes to the queue_adapter' do
|
|
58
|
-
message_attributes = {
|
|
59
|
-
'custom_tracing_id' => {
|
|
60
|
-
string_value: 'value',
|
|
61
|
-
data_type: 'String'
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
expect(queue_adapter).to receive(:enqueue) do |job|
|
|
65
|
-
expect(job.sqs_send_message_parameters[:message_attributes]).to eq(message_attributes)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
subject.set(message_attributes: message_attributes).perform_later 1, 2
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it 'passes message_system_attributes to the queue_adapter' do
|
|
72
|
-
message_system_attributes = {
|
|
73
|
-
'AWSTraceHeader' => {
|
|
74
|
-
string_value: 'trace_id',
|
|
75
|
-
data_type: 'String'
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
expect(queue_adapter).to receive(:enqueue) do |job|
|
|
79
|
-
expect(job.sqs_send_message_parameters[:message_system_attributes]).to eq(message_system_attributes)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
subject.set(message_system_attributes: message_system_attributes).perform_later 1, 2
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
end
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|