shoryuken 6.2.1 → 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.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/base.Dockerfile +1 -1
  3. data/.github/workflows/push.yml +36 -0
  4. data/.github/workflows/specs.yml +40 -30
  5. data/.github/workflows/verify-action-pins.yml +16 -0
  6. data/.gitignore +2 -1
  7. data/.rspec +2 -1
  8. data/.rubocop.yml +6 -1
  9. data/.ruby-version +1 -0
  10. data/Appraisals +8 -27
  11. data/CHANGELOG.md +213 -139
  12. data/Gemfile +2 -7
  13. data/README.md +14 -26
  14. data/Rakefile +2 -0
  15. data/bin/cli/base.rb +1 -2
  16. data/bin/cli/sqs.rb +13 -5
  17. data/bin/shoryuken +2 -1
  18. data/docker-compose.yml +22 -0
  19. data/gemfiles/rails_7_0.gemfile +10 -13
  20. data/gemfiles/rails_7_1.gemfile +19 -0
  21. data/gemfiles/rails_7_2.gemfile +19 -0
  22. data/gemfiles/rails_8_0.gemfile +19 -0
  23. data/lib/shoryuken/body_parser.rb +3 -1
  24. data/lib/shoryuken/client.rb +2 -0
  25. data/lib/shoryuken/default_exception_handler.rb +2 -0
  26. data/lib/shoryuken/default_worker_registry.rb +11 -11
  27. data/lib/shoryuken/environment_loader.rb +6 -6
  28. data/lib/shoryuken/extensions/active_job_adapter.rb +13 -6
  29. data/lib/shoryuken/extensions/active_job_concurrent_send_adapter.rb +5 -5
  30. data/lib/shoryuken/extensions/active_job_extensions.rb +2 -0
  31. data/lib/shoryuken/fetcher.rb +4 -2
  32. data/lib/shoryuken/helpers/atomic_boolean.rb +44 -0
  33. data/lib/shoryuken/helpers/atomic_counter.rb +104 -0
  34. data/lib/shoryuken/helpers/atomic_hash.rb +182 -0
  35. data/lib/shoryuken/helpers/hash_utils.rb +56 -0
  36. data/lib/shoryuken/helpers/string_utils.rb +65 -0
  37. data/lib/shoryuken/inline_message.rb +22 -0
  38. data/lib/shoryuken/launcher.rb +2 -0
  39. data/lib/shoryuken/logging.rb +19 -5
  40. data/lib/shoryuken/manager.rb +15 -5
  41. data/lib/shoryuken/message.rb +2 -0
  42. data/lib/shoryuken/middleware/chain.rb +2 -0
  43. data/lib/shoryuken/middleware/server/active_record.rb +2 -0
  44. data/lib/shoryuken/middleware/server/auto_delete.rb +2 -0
  45. data/lib/shoryuken/middleware/server/auto_extend_visibility.rb +10 -10
  46. data/lib/shoryuken/middleware/server/exponential_backoff_retry.rb +5 -3
  47. data/lib/shoryuken/middleware/server/timing.rb +2 -0
  48. data/lib/shoryuken/options.rb +14 -5
  49. data/lib/shoryuken/polling/base_strategy.rb +126 -0
  50. data/lib/shoryuken/polling/queue_configuration.rb +103 -0
  51. data/lib/shoryuken/polling/strict_priority.rb +2 -0
  52. data/lib/shoryuken/polling/weighted_round_robin.rb +2 -0
  53. data/lib/shoryuken/processor.rb +5 -2
  54. data/lib/shoryuken/queue.rb +6 -4
  55. data/lib/shoryuken/runner.rb +9 -12
  56. data/lib/shoryuken/util.rb +6 -6
  57. data/lib/shoryuken/version.rb +3 -1
  58. data/lib/shoryuken/worker/default_executor.rb +2 -0
  59. data/lib/shoryuken/worker/inline_executor.rb +9 -2
  60. data/lib/shoryuken/worker.rb +2 -0
  61. data/lib/shoryuken/worker_registry.rb +2 -0
  62. data/lib/shoryuken.rb +11 -34
  63. data/renovate.json +16 -0
  64. data/shoryuken.gemspec +7 -4
  65. data/spec/integration/launcher_spec.rb +3 -4
  66. data/spec/shared_examples_for_active_job.rb +13 -8
  67. data/spec/shoryuken/body_parser_spec.rb +2 -4
  68. data/spec/shoryuken/client_spec.rb +1 -1
  69. data/spec/shoryuken/default_exception_handler_spec.rb +9 -10
  70. data/spec/shoryuken/default_worker_registry_spec.rb +1 -2
  71. data/spec/shoryuken/environment_loader_spec.rb +9 -8
  72. data/spec/shoryuken/extensions/active_job_adapter_spec.rb +2 -1
  73. data/spec/shoryuken/extensions/active_job_base_spec.rb +2 -1
  74. data/spec/shoryuken/extensions/active_job_concurrent_send_adapter_spec.rb +2 -1
  75. data/spec/shoryuken/extensions/active_job_wrapper_spec.rb +2 -1
  76. data/spec/shoryuken/fetcher_spec.rb +23 -26
  77. data/spec/shoryuken/helpers/atomic_boolean_spec.rb +196 -0
  78. data/spec/shoryuken/helpers/atomic_counter_spec.rb +177 -0
  79. data/spec/shoryuken/helpers/atomic_hash_spec.rb +307 -0
  80. data/spec/shoryuken/helpers/hash_utils_spec.rb +145 -0
  81. data/spec/shoryuken/helpers/string_utils_spec.rb +124 -0
  82. data/spec/shoryuken/helpers_integration_spec.rb +96 -0
  83. data/spec/shoryuken/inline_message_spec.rb +196 -0
  84. data/spec/shoryuken/launcher_spec.rb +1 -2
  85. data/spec/shoryuken/manager_spec.rb +1 -2
  86. data/spec/shoryuken/middleware/chain_spec.rb +1 -1
  87. data/spec/shoryuken/middleware/server/auto_delete_spec.rb +1 -1
  88. data/spec/shoryuken/middleware/server/auto_extend_visibility_spec.rb +1 -1
  89. data/spec/shoryuken/middleware/server/exponential_backoff_retry_spec.rb +1 -1
  90. data/spec/shoryuken/middleware/server/timing_spec.rb +1 -1
  91. data/spec/shoryuken/options_spec.rb +4 -4
  92. data/spec/shoryuken/polling/base_strategy_spec.rb +280 -0
  93. data/spec/shoryuken/polling/queue_configuration_spec.rb +195 -0
  94. data/spec/shoryuken/polling/strict_priority_spec.rb +1 -1
  95. data/spec/shoryuken/polling/weighted_round_robin_spec.rb +1 -1
  96. data/spec/shoryuken/processor_spec.rb +1 -1
  97. data/spec/shoryuken/queue_spec.rb +2 -3
  98. data/spec/shoryuken/runner_spec.rb +1 -3
  99. data/spec/shoryuken/util_spec.rb +1 -1
  100. data/spec/shoryuken/worker/default_executor_spec.rb +1 -1
  101. data/spec/shoryuken/worker/inline_executor_spec.rb +57 -1
  102. data/spec/shoryuken/worker_spec.rb +15 -11
  103. data/spec/shoryuken_spec.rb +1 -1
  104. data/spec/spec_helper.rb +19 -4
  105. metadata +79 -35
  106. data/.codeclimate.yml +0 -20
  107. data/.github/FUNDING.yml +0 -12
  108. data/.github/dependabot.yml +0 -6
  109. data/.github/workflows/stale.yml +0 -20
  110. data/.reek.yml +0 -5
  111. data/gemfiles/aws_sdk_core_2.gemfile +0 -21
  112. data/gemfiles/rails_4_2.gemfile +0 -20
  113. data/gemfiles/rails_5_2.gemfile +0 -21
  114. data/gemfiles/rails_6_0.gemfile +0 -21
  115. data/gemfiles/rails_6_1.gemfile +0 -21
  116. data/lib/shoryuken/core_ext.rb +0 -69
  117. data/lib/shoryuken/polling/base.rb +0 -67
  118. data/shoryuken.jpg +0 -0
  119. data/spec/shoryuken/core_ext_spec.rb +0 -40
data/Gemfile CHANGED
@@ -5,19 +5,14 @@ gemspec
5
5
 
6
6
  group :test do
7
7
  gem 'activejob'
8
- gem 'aws-sdk-core', '~> 3'
9
- # Pin to 1.65.0 because of below issues:
10
- # - https://github.com/ruby-shoryuken/shoryuken/pull/753#issuecomment-1822720647
11
- # - https://github.com/getmoto/moto/issues/7054
12
- gem 'aws-sdk-sqs', '1.65.0'
13
- gem 'codeclimate-test-reporter', require: nil
14
8
  gem 'httparty'
15
9
  gem 'multi_xml'
16
10
  gem 'simplecov'
11
+ gem 'warning'
17
12
  end
18
13
 
19
14
  group :development do
20
15
  gem 'appraisal', git: 'https://github.com/thoughtbot/appraisal.git'
21
16
  gem 'pry-byebug'
22
- gem 'rubocop', '<= 1.12'
17
+ gem 'rubocop'
23
18
  end
data/README.md CHANGED
@@ -1,29 +1,25 @@
1
- **I'm looking for Shoryuken maintainers, are you interested on helping to maintain Shoryuken? [Join our Slack](https://join.slack.com/t/shoryuken/shared_invite/zt-19xjq3iqc-KmoJ6eU6~qvZNqcLzIrjww)**
2
-
3
1
  # Shoryuken
4
2
 
5
- ![Shoryuken](shoryuken.jpg)
6
-
7
3
  Shoryuken _sho-ryu-ken_ is a super-efficient [Amazon SQS](https://aws.amazon.com/sqs/) thread-based message processor.
8
4
 
9
5
  [![Build Status](https://github.com/ruby-shoryuken/shoryuken/workflows/Specs/badge.svg)](https://github.com/ruby-shoryuken/shoryuken/actions)
10
- [![Code Climate](https://codeclimate.com/github/phstc/shoryuken/badges/gpa.svg)](https://codeclimate.com/github/phstc/shoryuken)
6
+ [![Join the chat at https://slack.shoryuken.io](https://raw.githubusercontent.com/karafka/misc/master/slack.svg)](https://slack.shoryuken.io)
11
7
 
12
8
  ## Key features
13
9
 
14
- - [Rails Active Job](https://github.com/phstc/shoryuken/wiki/Rails-Integration-Active-Job)
15
- - [Queue Load balancing](https://github.com/phstc/shoryuken/wiki/Shoryuken-options#load-balancing)
16
- - [Concurrency per queue](https://github.com/phstc/shoryuken/wiki/Processing-Groups)
17
- - [Long Polling](https://github.com/phstc/shoryuken/wiki/Long-Polling)
18
- - [Batch processing](https://github.com/phstc/shoryuken/wiki/Worker-options#batch)
19
- - [Auto extend visibility timeout](https://github.com/phstc/shoryuken/wiki/Worker-options#auto_visibility_timeout)
20
- - [Exponential backoff](https://github.com/phstc/shoryuken/wiki/Worker-options#retry_intervals)
21
- - [Middleware support](https://github.com/phstc/shoryuken/wiki/Middleware)
10
+ - [Rails Active Job](https://github.com/ruby-shoryuken/shoryuken/wiki/Rails-Integration-Active-Job)
11
+ - [Queue Load balancing](https://github.com/ruby-shoryuken/shoryuken/wiki/Shoryuken-options#load-balancing)
12
+ - [Concurrency per queue](https://github.com/ruby-shoryuken/shoryuken/wiki/Processing-Groups)
13
+ - [Long Polling](https://github.com/ruby-shoryuken/shoryuken/wiki/Long-Polling)
14
+ - [Batch processing](https://github.com/ruby-shoryuken/shoryuken/wiki/Worker-options#batch)
15
+ - [Auto extend visibility timeout](https://github.com/ruby-shoryuken/shoryuken/wiki/Worker-options#auto_visibility_timeout)
16
+ - [Exponential backoff](https://github.com/ruby-shoryuken/shoryuken/wiki/Worker-options#retry_intervals)
17
+ - [Middleware support](https://github.com/ruby-shoryuken/shoryuken/wiki/Middleware)
22
18
  - Amazon SQS CLI. See `shoryuken help sqs`
23
19
 
24
20
  ## Requirements
25
21
 
26
- Ruby 2.4 or greater.
22
+ Ruby 3.0 or greater.
27
23
 
28
24
  ## Installation
29
25
 
@@ -33,14 +29,6 @@ Add this line to your application's Gemfile:
33
29
  gem 'shoryuken'
34
30
  ```
35
31
 
36
- If you are using AWS SDK version 3, please also add this line:
37
-
38
- ```ruby
39
- gem 'aws-sdk-sqs'
40
- ```
41
-
42
- The extra gem `aws-sdk-sqs` is required in order to keep Shoryuken compatible with AWS SDK version 2 and 3.
43
-
44
32
  And then execute:
45
33
 
46
34
  ```shell
@@ -49,11 +37,11 @@ $ bundle
49
37
 
50
38
  ## Usage
51
39
 
52
- Check the [Getting Started](https://github.com/phstc/shoryuken/wiki/Getting-Started) page.
40
+ Check the [Getting Started](https://github.com/ruby-shoryuken/shoryuken/wiki/Getting-Started) page.
53
41
 
54
42
  ## More Information
55
43
 
56
- For more information check the [wiki page](https://github.com/phstc/shoryuken/wiki).
44
+ For more information check the [wiki page](https://github.com/ruby-shoryuken/shoryuken/wiki).
57
45
 
58
46
  ## Credits
59
47
 
@@ -61,7 +49,7 @@ For more information check the [wiki page](https://github.com/phstc/shoryuken/wi
61
49
 
62
50
  ## Contributing
63
51
 
64
- 1. Fork it ( https://github.com/phstc/shoryuken/fork )
52
+ 1. Fork it ( https://github.com/ruby-shoryuken/shoryuken/fork )
65
53
  2. Create your feature branch (`git checkout -b my-new-feature`)
66
54
  3. Commit your changes (`git commit -am 'Add some feature'`)
67
55
  4. Push to the branch (`git push origin my-new-feature`)
@@ -69,7 +57,7 @@ For more information check the [wiki page](https://github.com/phstc/shoryuken/wi
69
57
 
70
58
  ### Testing
71
59
 
72
- To run all unit specs against the latest dependency vesions, execute
60
+ To run all unit specs against the latest dependency versions, execute
73
61
 
74
62
  ```sh
75
63
  bundle exec rake spec
data/Rakefile CHANGED
@@ -1,4 +1,6 @@
1
+ require 'bundler/setup'
1
2
  require 'bundler/gem_tasks'
3
+
2
4
  $stdout.sync = true
3
5
 
4
6
  begin
data/bin/cli/base.rb CHANGED
@@ -25,8 +25,7 @@ module Shoryuken
25
25
 
26
26
  def print_format_column(column, size)
27
27
  size_with_padding = size + 4
28
- column = column.to_s.ljust(size_with_padding)
29
- column
28
+ column.to_s.ljust(size_with_padding)
30
29
  end
31
30
 
32
31
  def fail_task(msg, quit = true)
data/bin/cli/sqs.rb CHANGED
@@ -5,7 +5,7 @@ module Shoryuken
5
5
  module CLI
6
6
  class SQS < Base
7
7
  # See https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/quotas-messages.html
8
- MAX_BATCH_SIZE = 256 * 1024
8
+ MAX_BATCH_SIZE = 1024 * 1024
9
9
 
10
10
  namespace :sqs
11
11
  class_option :endpoint, aliases: '-e', type: :string, default: ENV['SHORYUKEN_SQS_ENDPOINT'], desc: 'Endpoint URL'
@@ -14,10 +14,17 @@ module Shoryuken
14
14
  def normalize_dump_message(message)
15
15
  # symbolize_keys is needed for keeping it compatible with `requeue`
16
16
  attributes = message[:attributes].symbolize_keys
17
+
18
+ # See https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_MessageAttributeValue.html
19
+ # The `string_list_values` and `binary_list_values` are not implemented. Reserved for future use.
20
+ message_attributes = message[:message_attributes].each_with_object({}) do |(k, v), result|
21
+ result[k] = v.slice(:data_type, :string_value, :binary_value)
22
+ end
23
+
17
24
  {
18
25
  id: message[:message_id],
19
26
  message_body: message[:body],
20
- message_attributes: message[:message_attributes],
27
+ message_attributes: message_attributes,
21
28
  message_deduplication_id: attributes[:MessageDeduplicationId],
22
29
  message_group_id: attributes[:MessageGroupId]
23
30
  }
@@ -104,7 +111,7 @@ module Shoryuken
104
111
  attribute_size + body_size
105
112
  end
106
113
 
107
- def find_all(url, limit)
114
+ def find_all(url, limit, &block)
108
115
  count = 0
109
116
  batch_size = limit > 10 ? 10 : limit
110
117
 
@@ -119,7 +126,7 @@ module Shoryuken
119
126
  message_attribute_names: ['All']
120
127
  ).messages || []
121
128
 
122
- messages.each { |m| yield m }
129
+ messages.each(&block)
123
130
 
124
131
  count += messages.size
125
132
 
@@ -205,7 +212,8 @@ module Shoryuken
205
212
  end
206
213
 
207
214
  desc 'requeue QUEUE-NAME PATH', 'Requeues messages from a dump file'
208
- method_option :batch_size, aliases: '-n', type: :numeric, default: 10, desc: 'maximum number of messages per batch to send'
215
+ method_option :batch_size, aliases: '-n', type: :numeric, default: 10,
216
+ desc: 'maximum number of messages per batch to send'
209
217
  def requeue(queue_name, path)
210
218
  fail_task "Path #{path} not found" unless File.exist?(path)
211
219
 
data/bin/shoryuken CHANGED
@@ -26,7 +26,8 @@ module Shoryuken
26
26
  method_option :logfile, aliases: '-L', type: :string, desc: 'Path to logfile'
27
27
  method_option :pidfile, aliases: '-P', type: :string, desc: 'Path to pidfile'
28
28
  method_option :verbose, aliases: '-v', type: :boolean, desc: 'Print more verbose output'
29
- method_option :delay, aliases: '-D', type: :numeric, desc: 'Number of seconds to pause fetching from an empty queue'
29
+ method_option :delay, aliases: '-D', type: :numeric,
30
+ desc: 'Number of seconds to pause fetching from an empty queue'
30
31
  def start
31
32
  opts = options.to_h.symbolize_keys
32
33
 
@@ -0,0 +1,22 @@
1
+ services:
2
+ localstack:
3
+ image: localstack/localstack:latest
4
+ container_name: localstack
5
+ ports:
6
+ - "4566:4566"
7
+ - "4510-4559:4510-4559"
8
+ environment:
9
+ - SERVICES=sqs
10
+ - DEBUG=${DEBUG:-0}
11
+ - DOCKER_HOST=unix:///var/run/docker.sock
12
+ - AWS_DEFAULT_REGION=us-east-1
13
+ - AWS_ACCESS_KEY_ID=test
14
+ - AWS_SECRET_ACCESS_KEY=test
15
+ volumes:
16
+ - "${LOCALSTACK_VOLUME_DIR:-./.localstack}:/var/lib/localstack"
17
+ - "/var/run/docker.sock:/var/run/docker.sock"
18
+ healthcheck:
19
+ test: ["CMD", "curl", "-f", "http://localhost:4566/_localstack/health"]
20
+ interval: 5s
21
+ timeout: 10s
22
+ retries: 5
@@ -1,22 +1,19 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
5
  group :test do
6
- gem "activejob", "~> 7.0"
7
- gem "aws-sdk-core", "~> 3"
8
- gem "aws-sdk-sqs"
9
- gem "codeclimate-test-reporter", require: nil
10
- gem "httparty"
11
- gem "multi_xml"
12
- gem "simplecov"
6
+ gem 'activejob', '~> 7.0'
7
+ gem 'httparty'
8
+ gem 'multi_xml'
9
+ gem 'simplecov'
10
+ gem 'warning'
13
11
  end
14
12
 
15
13
  group :development do
16
- gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git"
17
- gem "rubocop"
18
- gem "pry", ">= 0.14.2"
19
- gem "pry-byebug", ">= 3.10.1"
14
+ gem 'appraisal', git: 'https://github.com/thoughtbot/appraisal.git'
15
+ gem 'pry-byebug'
16
+ gem 'rubocop'
20
17
  end
21
18
 
22
- gemspec path: "../"
19
+ gemspec path: '../'
@@ -0,0 +1,19 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ group :test do
6
+ gem 'activejob', '~> 7.1'
7
+ gem 'httparty'
8
+ gem 'multi_xml'
9
+ gem 'simplecov'
10
+ gem 'warning'
11
+ end
12
+
13
+ group :development do
14
+ gem 'appraisal', git: 'https://github.com/thoughtbot/appraisal.git'
15
+ gem 'pry-byebug'
16
+ gem 'rubocop'
17
+ end
18
+
19
+ gemspec path: '../'
@@ -0,0 +1,19 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ group :test do
6
+ gem 'activejob', '~> 7.2'
7
+ gem 'httparty'
8
+ gem 'multi_xml'
9
+ gem 'simplecov'
10
+ gem 'warning'
11
+ end
12
+
13
+ group :development do
14
+ gem 'appraisal', git: 'https://github.com/thoughtbot/appraisal.git'
15
+ gem 'pry-byebug'
16
+ gem 'rubocop'
17
+ end
18
+
19
+ gemspec path: '../'
@@ -0,0 +1,19 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ group :test do
6
+ gem 'activejob', '~> 8.0'
7
+ gem 'httparty'
8
+ gem 'multi_xml'
9
+ gem 'simplecov'
10
+ gem 'warning'
11
+ end
12
+
13
+ group :development do
14
+ gem 'appraisal', git: 'https://github.com/thoughtbot/appraisal.git'
15
+ gem 'pry-byebug'
16
+ gem 'rubocop'
17
+ end
18
+
19
+ gemspec path: '../'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shoryuken
2
4
  class BodyParser
3
5
  class << self
@@ -16,7 +18,7 @@ module Shoryuken
16
18
  # JSON.parse
17
19
  body_parser.parse(sqs_msg.body)
18
20
  elsif body_parser.respond_to?(:load)
19
- # see https://github.com/phstc/shoryuken/pull/91
21
+ # see https://github.com/ruby-shoryuken/shoryuken/pull/91
20
22
  # JSON.load
21
23
  body_parser.load(sqs_msg.body)
22
24
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shoryuken
2
4
  class Client
3
5
  @@queues = {}
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shoryuken
2
4
  class DefaultExceptionHandler
3
5
  extend Util
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shoryuken
2
4
  class DefaultWorkerRegistry < WorkerRegistry
3
5
  def initialize
4
- @workers = Concurrent::Hash.new
6
+ @workers = Shoryuken::Helpers::AtomicHash.new
5
7
  end
6
8
 
7
9
  def batch_receive_messages?(queue)
@@ -19,10 +21,10 @@ module Shoryuken
19
21
  message.message_attributes['shoryuken_class'][:string_value]
20
22
 
21
23
  worker_class = begin
22
- worker_class.constantize
23
- rescue
24
- @workers[queue]
25
- end
24
+ Shoryuken::Helpers::StringUtils.constantize(worker_class)
25
+ rescue
26
+ @workers[queue]
27
+ end
26
28
 
27
29
  worker_class.new if worker_class
28
30
  end
@@ -32,12 +34,10 @@ module Shoryuken
32
34
  end
33
35
 
34
36
  def register_worker(queue, clazz)
35
- if (worker_class = @workers[queue])
36
- if worker_class.get_shoryuken_options['batch'] == true || clazz.get_shoryuken_options['batch'] == true
37
- fail ArgumentError, "Could not register #{clazz} for #{queue}, "\
38
- "because #{worker_class} is already registered for this queue, "\
39
- "and Shoryuken doesn't support a batchable worker for a queue with multiple workers"
40
- end
37
+ if (worker_class = @workers[queue]) && (worker_class.get_shoryuken_options['batch'] == true || clazz.get_shoryuken_options['batch'] == true)
38
+ fail ArgumentError, "Could not register #{clazz} for #{queue}, "\
39
+ "because #{worker_class} is already registered for this queue, "\
40
+ "and Shoryuken doesn't support a batchable worker for a queue with multiple workers"
41
41
  end
42
42
 
43
43
  @workers[queue] = clazz
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shoryuken
2
4
  class EnvironmentLoader
3
5
  attr_reader :options
@@ -44,7 +46,7 @@ module Shoryuken
44
46
  fail ArgumentError, "The supplied config file #{path} does not exist" unless File.exist?(path)
45
47
 
46
48
  if (result = YAML.load(ERB.new(IO.read(path)).result))
47
- result.deep_symbolize_keys
49
+ Shoryuken::Helpers::HashUtils.deep_symbolize_keys(result)
48
50
  else
49
51
  {}
50
52
  end
@@ -161,11 +163,9 @@ module Shoryuken
161
163
  non_existent_queues = []
162
164
 
163
165
  Shoryuken.ungrouped_queues.uniq.each do |queue|
164
- begin
165
- Shoryuken::Client.queues(queue)
166
- rescue Aws::Errors::NoSuchEndpointError, Aws::SQS::Errors::NonExistentQueue
167
- non_existent_queues << queue
168
- end
166
+ Shoryuken::Client.queues(queue)
167
+ rescue Aws::Errors::NoSuchEndpointError, Aws::SQS::Errors::NonExistentQueue
168
+ non_existent_queues << queue
169
169
  end
170
170
 
171
171
  return if non_existent_queues.none?
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # ActiveJob docs: http://edgeguides.rubyonrails.org/active_job_basics.html
2
4
  # Example adapters ref: https://github.com/rails/rails/tree/master/activejob/lib/active_job/queue_adapters
3
5
 
@@ -9,15 +11,15 @@ module ActiveJob
9
11
  #
10
12
  # Shoryuken ("sho-ryu-ken") is a super-efficient AWS SQS thread based message processor.
11
13
  #
12
- # Read more about Shoryuken {here}[https://github.com/phstc/shoryuken].
14
+ # Read more about Shoryuken {here}[https://github.com/ruby-shoryuken/shoryuken].
13
15
  #
14
16
  # To use Shoryuken set the queue_adapter config to +:shoryuken+.
15
17
  #
16
18
  # Rails.application.config.active_job.queue_adapter = :shoryuken
17
- class ShoryukenAdapter
19
+ class ShoryukenAdapter < ActiveJob::QueueAdapters::AbstractAdapter
18
20
  class << self
19
21
  def instance
20
- # https://github.com/phstc/shoryuken/pull/174#issuecomment-174555657
22
+ # https://github.com/ruby-shoryuken/shoryuken/pull/174#issuecomment-174555657
21
23
  @instance ||= new
22
24
  end
23
25
 
@@ -30,7 +32,12 @@ module ActiveJob
30
32
  end
31
33
  end
32
34
 
33
- def enqueue(job, options = {}) #:nodoc:
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:
34
41
  register_worker!(job)
35
42
 
36
43
  job.sqs_send_message_parameters.merge! options
@@ -41,7 +48,7 @@ module ActiveJob
41
48
  queue.send_message send_message_params
42
49
  end
43
50
 
44
- def enqueue_at(job, timestamp) #:nodoc:
51
+ def enqueue_at(job, timestamp) # :nodoc:
45
52
  enqueue(job, delay_seconds: calculate_delay(timestamp))
46
53
  end
47
54
 
@@ -80,7 +87,7 @@ module ActiveJob
80
87
  Shoryuken.register_worker(job.queue_name, JobWrapper)
81
88
  end
82
89
 
83
- class JobWrapper #:nodoc:
90
+ class JobWrapper # :nodoc:
84
91
  include Shoryuken::Worker
85
92
 
86
93
  shoryuken_options body_parser: :json, auto_delete: true
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # ActiveJob docs: http://edgeguides.rubyonrails.org/active_job_basics.html
2
4
  # Example adapters ref: https://github.com/rails/rails/tree/master/activejob/lib/active_job/queue_adapters
3
5
  module ActiveJob
@@ -30,11 +32,9 @@ module ActiveJob
30
32
  end
31
33
 
32
34
  def error_handler
33
- @error_handler ||= begin
34
- lambda { |error, job, _options|
35
- Shoryuken.logger.warn("Failed to enqueue job: #{job.inspect} due to error: #{error}")
36
- }
37
- end
35
+ @error_handler ||= lambda { |error, job, _options|
36
+ Shoryuken.logger.warn("Failed to enqueue job: #{job.inspect} due to error: #{error}")
37
+ }
38
38
  end
39
39
 
40
40
  private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shoryuken
2
4
  module ActiveJobExtensions
3
5
  # Adds an accessor for SQS SendMessage parameters on ActiveJob jobs
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shoryuken
2
4
  class Fetcher
3
5
  include Util
@@ -30,13 +32,13 @@ module Shoryuken
30
32
 
31
33
  begin
32
34
  yield
33
- rescue => ex
35
+ rescue => e
34
36
  # Tries to auto retry connectivity errors
35
37
  raise if attempts >= max_attempts
36
38
 
37
39
  attempts += 1
38
40
 
39
- logger.debug { "Retrying fetch attempt #{attempts} for #{ex.message}" }
41
+ logger.debug { "Retrying fetch attempt #{attempts} for #{e.message}" }
40
42
 
41
43
  sleep((1..5).to_a.sample)
42
44
 
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shoryuken
4
+ module Helpers
5
+ # A thread-safe boolean implementation using AtomicCounter as base.
6
+ # Drop-in replacement for Concurrent::AtomicBoolean without external dependencies.
7
+ # Uses 1 for true and 0 for false internally.
8
+ class AtomicBoolean < AtomicCounter
9
+ # Prevent misuse of counter operations on a boolean
10
+ undef_method :increment, :decrement
11
+
12
+ def initialize(initial_value = false)
13
+ super(initial_value ? 1 : 0)
14
+ end
15
+
16
+ # Get the current value as boolean
17
+ def value
18
+ super != 0
19
+ end
20
+
21
+ # Set the value to true
22
+ def make_true
23
+ @mutex.synchronize { @value = 1 }
24
+ true
25
+ end
26
+
27
+ # Set the value to false
28
+ def make_false
29
+ @mutex.synchronize { @value = 0 }
30
+ false
31
+ end
32
+
33
+ # Check if the value is true
34
+ def true?
35
+ @mutex.synchronize { @value != 0 }
36
+ end
37
+
38
+ # Check if the value is false
39
+ def false?
40
+ @mutex.synchronize { @value == 0 }
41
+ end
42
+ end
43
+ end
44
+ end