-
-
Notifications
You must be signed in to change notification settings - Fork 275
Complete Shoryuken Setup for Rails 5 with ActiveJob
Pablo Cantero edited this page Oct 4, 2019
·
8 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
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