Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require: rubocop-performance

Metrics/LineLength:
Layout/LineLength:
Max: 120
Exclude:
- 'spec/**/*'
Expand Down
25 changes: 25 additions & 0 deletions lib/turtle/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Turtle
class Railtie < ::Rails::Railtie
config.before_initialize do
overwrite_eager_load

if ENV['AWS_SQS_ENDPOINT'].present?
Shoryuken.sqs_client = Aws::SQS::Client.new(
endpoint: ENV['AWS_SQS_ENDPOINT']
Expand All @@ -21,5 +23,28 @@ class Railtie < ::Rails::Railtie
end
end
end

# Set rails eager_load to true when running shoryuken in a rails project.
# This is needed because otherwise workers show the message "No worker found" when trying to process messages
# received from a topic.
#
# Messages enqueued using perform_async are not affected because they contain metadata informing the class name,
# as can be seen at:
# https://github.com/ruby-shoryuken/shoryuken/blob/546e4b81afbbacdc7ed6d742a96025be4616f292/lib/shoryuken/worker/default_executor.rb#L7-L10
#
# However, the code below used to define which worker to use only works when perform_async above is used.
# https://github.com/ruby-shoryuken/shoryuken/blob/546e4b81afbbacdc7ed6d742a96025be4616f292/lib/shoryuken/default_worker_registry.rb#L15-L28
#
# Therefore the following code is needed.

Copy link

Copilot AI May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This helper method is public by default; marking it as private will prevent unintended external calls and improve encapsulation.

Suggested change
private

Copilot uses AI. Check for mistakes.
def overwrite_eager_load
# $PROGRAM_NAME returns the name of the script being executed, i.e. "/usr/local/bundle/bin/shoryuken"
return if $PROGRAM_NAME.to_s.split('/').last.downcase != 'shoryuken'
Comment on lines +41 to +42
Copy link

Copilot AI May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Relying on $PROGRAM_NAME string matching can be brittle; consider detecting Shoryuken via a dedicated environment variable or CLI flag if available.

Suggested change
# $PROGRAM_NAME returns the name of the script being executed, i.e. "/usr/local/bundle/bin/shoryuken"
return if $PROGRAM_NAME.to_s.split('/').last.downcase != 'shoryuken'
# Check for the presence of the SHORYUKEN_MODE environment variable
return unless ENV['SHORYUKEN_MODE'] == 'true'

Copilot uses AI. Check for mistakes.
return unless defined?(::Rails)
return if ::Rails.application.config.eager_load == true

Logger.info('Shoryuken and rails detected, overwriting ::Rails.application.config.eager_load to true')
Copy link

Copilot AI May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Logger.info may not integrate with Rails logging. Consider using Rails.logger.info so this message appears in the Rails logs.

Suggested change
Logger.info('Shoryuken and rails detected, overwriting ::Rails.application.config.eager_load to true')
Rails.logger.info('Shoryuken and rails detected, overwriting ::Rails.application.config.eager_load to true')

Copilot uses AI. Check for mistakes.
::Rails.application.config.eager_load = true
end
end
end