-
Notifications
You must be signed in to change notification settings - Fork 290
Complete Shoryuken Setup for Rails 5 with ActiveJob
Adrian Teh edited this page Nov 22, 2017
·
9 revisions
Been searching everywhere for a complete setup guide with Rails 5 and ActiveJob. There are bits and pieces everywhere scattered on outdated articles. Here's my stab at making it easier. Hope this helps!
Login to your Amazon AWS Console and go to SQS to create the queue
gem 'shoryuken'
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
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
aws:
access_key_id: ENV['AWS_ACCESS_KEY_ID']
region: ENV['AWS_REGION']
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
concurrency: 15
queues:
- [name_of_your_queue_in_sqs, 1]
bundle exec shoryuken -R -C config/shoryuken.yml