-
Notifications
You must be signed in to change notification settings - Fork 0
Eager loads rails projects when running shoryuken #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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/**/*' | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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'] | ||||||||||
|
|
@@ -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. | ||||||||||
|
|
||||||||||
| 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
|
||||||||||
| # $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
AI
May 30, 2025
There was a problem hiding this comment.
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.
| 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') |
There was a problem hiding this comment.
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
privatewill prevent unintended external calls and improve encapsulation.