Git Product home page Git Product logo

activejob's Introduction

Active Job -- Make work happen later

Active Job is a framework for declaring jobs and making them run on a variety of queueing backends. These jobs can be everything from regularly scheduled clean-ups, billing charges, or mailings. Anything that can be chopped up into small units of work and run in parallel, really.

It also serves as the backend for ActionMailer's #deliver_later functionality that makes it easy to turn any mailing into a job for running later. That's one of the most common jobs in a modern web application: Sending emails outside of the request-response cycle, so the user doesn't have to wait on it.

The main point is to ensure that all Rails apps will have a job infrastructure in place, even if it's in the form of an "immediate runner". We can then have framework features and other gems build on top of that, without having to worry about API differences between Delayed Job and Resque. Picking your queuing backend becomes more of an operational concern, then. And you'll be able to switch between them without having to rewrite your jobs.

Usage

Set the queue adapter for Active Job:

ActiveJob::Base.queue_adapter = :inline # default queue adapter
# Adapters currently supported: :delayed_job, :que, :queue_classic, :resque,
#                               :sidekiq, :sneakers, :sucker_punch

Declare a job like so:

class MyJob < ActiveJob::Base
  queue_as :my_jobs

  def perform(record)
    record.do_work
  end
end

Enqueue a job like so:

MyJob.enqueue record

That's it!

GlobalID support

Active Job supports GlobalID serialization for parameters. This makes it possible to pass live Active Record objects to your job instead of class/id pairs, which you then have to manually deserialize. Before, jobs would look like this:

class TrashableCleanupJob
  def perform(trashable_class, trashable_id, depth)
    trashable = trashable_class.constantize.find(trashable_id)
    trashable.cleanup(depth)
  end
end

Now you can simply do:

class TrashableCleanupJob
  def perform(trashable, depth)
    trashable.cleanup(depth)
  end
end

This works with any class that mixes in ActiveModel::GlobalIdentification, which by default has been mixed into Active Record classes.

Supported queueing systems

We currently have adapters for:

We would like to have adapters for:

Under development as a gem, targeted for Rails inclusion

Active Job is currently being developed in a separate repository until it's ready to be merged in with Rails. The current plan is to have Active Job be part of the Rails 4.2 release, but plans may change depending on when this framework stabilizes and feels ready.

License

Active Job is released under the MIT license:

activejob's People

Contributors

dhh avatar mperham avatar rafaelfranca avatar seuros avatar cristianbica avatar douwem avatar larrylv avatar guilleiguaran avatar pecha7x avatar mytrile avatar aesthetikx avatar zhouguangming avatar

Watchers

James Cloos avatar  avatar

Forkers

gymsales

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.