Skip to content

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!

Create SQS queue

Login to your Amazon AWS Console and go to SQS to create the queue

Install gem

gem 'shoryuken'

Note: aws-sdk gem is not necessary

Configure your rails application to use Shoryuken

# config/application.rb
module YourRailsApp
  class Application < Rails::Application
    config.active_job.queue_adapter = :shoryuken
  end
end

Create your job

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

Configure shoryuken.yml

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]

Run the following command to start consuming the SQS queue

bundle exec shoryuken -R -C config/shoryuken.yml

Clone this wiki locally