rails--rails/activejob
Yves Senn 48a183ecb9 use `assert_not` instead of `refute` as mentioned in our guides.
As described in the "Follow Coding Conventions" section in our
contribution guide (http://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#follow-the-coding-conventions)
we favor `assert_not` over `refute`.

While we don't usually make stylistic changes on it's own I opted to do
it in this case. The reason being that test cases are usually copied as
a starting point for new tests. This results in a spread of `refute` in
files that have been using it already.
2015-08-13 09:20:39 +02:00
..
lib Make assert_enqueued_with and assert_performed_with returns the matched job 2015-08-10 20:14:42 -04:00
test use `assert_not` instead of `refute` as mentioned in our guides. 2015-08-13 09:20:39 +02:00
.gitignore ActiveJob Integration Tests 2014-09-11 00:38:56 +03:00
CHANGELOG.md Make assert_enqueued_with and assert_performed_with returns the matched job 2015-08-10 20:14:42 -04:00
MIT-LICENSE Update copyright notices to 2015 [ci skip] 2014-12-31 08:34:14 +01:00
README.md [ci skip] Don’t encourage `sudo gem install` 2015-05-12 14:51:19 -07:00
Rakefile Remove unused package tasks 2015-05-28 09:06:10 +02:00
activejob.gemspec Upgrade to Ruby 2.2.2 2015-04-14 08:41:56 +05:30

README.md

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, to billing charges, to mailings. Anything that can be chopped up into small units of work and run in parallel, really.

It also serves as the backend for Action Mailer'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

Note: To learn how to use your preferred queueing backend see its adapter documentation at ActiveJob::QueueAdapters.

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.perform_later record  # Enqueue a job to be performed as soon the queueing system is free.
MyJob.set(wait_until: Date.tomorrow.noon).perform_later(record)  # Enqueue a job to be performed tomorrow at noon.
MyJob.set(wait: 1.week).perform_later(record) # Enqueue a job to be performed 1 week from now.

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 GlobalID::Identification, which by default has been mixed into Active Record classes.

Supported queueing systems

Active Job has built-in adapters for multiple queueing backends (Sidekiq, Resque, Delayed Job and others). To get an up-to-date list of the adapters see the API Documentation for ActiveJob::QueueAdapters.

Auxiliary gems

Download and installation

The latest version of Active Job can be installed with RubyGems:

  % gem install activejob

Source code can be downloaded as part of the Rails project on GitHub

License

Active Job is released under the MIT license:

Support

API documentation is at:

Bug reports can be filed for the Ruby on Rails project here:

Feature requests should be discussed on the rails-core mailing list here: