-
-
Notifications
You must be signed in to change notification settings - Fork 280
Complete Shoryuken Setup for Rails 5 with ActiveJob
David Beitey edited this page Jun 21, 2024
·
9 revisions
Login to your Amazon AWS Console and go to SQS to create the queue or use the Shoryuken CLI.
shoryuken sqs create QUEUE-NAME
See shoryuken sqs help create
.
gem 'shoryuken'
gem 'aws-sdk-sqs'
Note: aws-sdk
gem is not necessary.
# config/application.rb
module YourRailsApp
class Application < Rails::Application
config.active_job.queue_adapter = :shoryuken
config.autoload_paths << "#{Rails.root}/app/jobs"
# For jobs not otherwise autoloaded add the following:
config.eager_load_paths << "#{Rails.root}/app/jobs"
end
end
# app/jobs/your_job.rb
class YourJob < ApplicationJob
queue_as 'name_of_your_sqs_queue'
def perform(resource_id)
resource = Resource.find(resource_id)
# perform your task on resource ...
end
end
Trigger your job where required:
YourJob.perform_later(resource.id)
Make sure it's located in config/shoryuken.yml
. This will be used by the worker to consume and process the messages sent to the queue in SQS.
concurrency: 15
queues:
- [name_of_your_queue_in_sqs, 1]
- [<%= ENV['OTHER_QUEUE'] %>, 1]
You can use dotenv to setup your environment variables.
The number 1
above after the queue name is the queue weight, please refer to Polling strategies
for more information.
bundle exec shoryuken -R -C config/shoryuken.yml