Skip to content

Conversation

@rubendebest
Copy link
Contributor

@rubendebest rubendebest commented May 30, 2025

# 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.

@rubendebest rubendebest requested review from a team, Copilot and rhiroyuki May 30, 2025 23:09
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ensures that Rails eager loading is enabled when running Shoryuken so background workers are discovered correctly and corrects a RuboCop configuration.

  • Add a Railtie hook (overwrite_eager_load) to turn on config.eager_load for Shoryuken processes
  • Fix the LineLength cop name in .rubocop.yml from Metrics/LineLength to Layout/LineLength

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
lib/turtle/railtie.rb Introduce overwrite_eager_load method and invoke it before initialization when running via Shoryuken
.rubocop.yml Update cop name from Metrics/LineLength to Layout/LineLength
Comments suppressed due to low confidence (2)

lib/turtle/railtie.rb:40

  • [nitpick] The method name overwrite_eager_load is generic; consider renaming it to something more descriptive like enable_eager_load_for_shoryuken to clarify its intent.
def overwrite_eager_load

lib/turtle/railtie.rb:40

  • There are no existing tests for this new eager load behavior. Adding unit or integration tests to verify that eager_load is toggled only under Shoryuken will prevent regressions.
def overwrite_eager_load

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.
# 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.
Comment on lines +41 to +42
# $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'
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.
@rubendebest rubendebest merged commit 46c34ee into master May 31, 2025
2 checks passed
@rubendebest rubendebest deleted the eager-load-rails branch May 31, 2025 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants