Giter Club home page Giter Club logo

delayed_job_sqs's Introduction

This is an Amazon SQS backend for delayed_job

Getting Started

Get credentials

To start using delayed_job_sqs, you need to sign up for an AWS account and setup your credentials.

  1. Go to https://portal.aws.amazon.com/gp/aws/developer/registration/index.html and sign up.
  2. Get your AWS Access Key Id & Secret Access Key for your account.
  3. Either require 'aws-sdk' and call AWS.config() prior to require 'delayed_job_sqs', or create an aws.yml that will get loaded with your app. You will need to configure Delayed::Worker below to pass in the YAML file location:
[aws]
  access_key_id: <your access key>
  secret_access_key: <your secret key>

Or if using Rails, create config/initializers/aws-sdk.rb and put the following into the file:

AWS.config({
  access_key_id: '<your access key>',
  secret_access_key: '<your secret key>',
})

Installation

Add the gems to your Gemfile:

gem 'delayed_job'
gem 'delayed_job_sqs'

Optionally: Add an initializer (config/initializers/delayed_job.rb):

Delayed::Worker.configure do |config|
  # optional params:
  config.aws_config = '~/stuff/things/aws.yml' # Specify the file location of the AWS configuration YAML if you're not using Rails and you want to use a YAML file instead of calling AWS.config
  config.default_queue_name = 'default' # Specify an alternative default queue name
  config.delay_seconds = # Sets the default delay in seconds for messages sent to the queue.
  config.message_retention_period = 345600 # The number of seconds Amazon SQS retains a message. Must be an integer from 3600 (1 hour) to 1209600 (14 days). The default for this attribute is 345600 (4 days).
  config.visibility_timeout = 30 # The length of time (in seconds) that a message received from a queue will be invisible to other receiving components when they ask to receive messages. Valid values: integers from 0 to 43200 (12 hours).
  config.wait_time_seconds = # How many seconds to wait for a response
end

Usage

That's it. Use delayed_job as normal.

Example:

class User
  def background_stuff
    puts "I run in the background"
  end
end

Then in one of your controllers:

user = User.new
user.delay.background_stuff

Start worker process

rake jobs:work

If you want to process a specific queue that's not in your initializer or called default, use the QUEUE or QUEUES environment variable:

QUEUE=tracking rake jobs:work

That will start pulling jobs off the default queue and processing them. The gem will also handle multiple named queues if you have configured rake or scripts/delayed_job accordingly however be sure to name the queue when putting objects on the queue:

user = User.new
user.delay(queue: 'bestest_queue').background_stuff

delayed_job_sqs's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.