1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #17068 from mokhan/update-active-job-documentation

[ci-skip] Update Active Job API documentation
This commit is contained in:
Abdelkader Boudih 2014-10-02 18:10:55 +01:00
commit 4cd57a88b4
6 changed files with 64 additions and 5 deletions

View file

@ -24,10 +24,16 @@ module ActiveJob
extend self extend self
TYPE_WHITELIST = [ NilClass, Fixnum, Float, String, TrueClass, FalseClass, Bignum ] TYPE_WHITELIST = [ NilClass, Fixnum, Float, String, TrueClass, FalseClass, Bignum ]
# Serializes a set of arguments. Whitelisted types are returned
# as-is. Arrays/Hashes are serialized element by element.
# All other types are serialized using GlobalID.
def serialize(arguments) def serialize(arguments)
arguments.map { |argument| serialize_argument(argument) } arguments.map { |argument| serialize_argument(argument) }
end end
# Deserializes a set of arguments. Whitelisted types are returned
# as-is. Arrays/Hashes are deserialized element by element.
# All other types are deserialized using GlobalID.
def deserialize(arguments) def deserialize(arguments)
arguments.map { |argument| deserialize_argument(argument) } arguments.map { |argument| deserialize_argument(argument) }
rescue => e rescue => e

View file

@ -6,7 +6,48 @@ require 'active_job/execution'
require 'active_job/callbacks' require 'active_job/callbacks'
require 'active_job/logging' require 'active_job/logging'
module ActiveJob module ActiveJob #:nodoc:
# = Active Job
#
# Active job objects can be configured to work with different backend
# queuing frameworks. To specify a queue adapter to use:
#
# ActiveJob::Base.queue_adapter = :inline
#
# A list of supported adapters can be found in QueueAdapters.
#
# Active job objects can be defined by creating a class that inherits
# from the ActiveJob::Base class. The only necessary method to
# implement is the "perform" method.
#
# To define an Active Job object:
#
# class ProcessPhotoJob < ActiveJob::Base
# def perform(photo)
# photo.watermark!('Rails')
# photo.rotate!(90.degrees)
# photo.resize_to_fit!(300, 300)
# photo.upload!
# end
# end
#
# Records that are passed in are serialized/deserialized using Global
# Id. More information can be found in Arguments.
#
# To queue a job to be processed asynchronously immediately:
#
# ProcessPhotoJob.perform_later(photo)
#
# To queue a job to be processed at some point in the future:
#
# ProcessPhotoJob.set(wait_until: Date.tomorrow.noon).perform_later(photo)
#
# More information can be found in ActiveJob::Core::ClassMethods#set
#
# == Exceptions
#
# * DeserializationError - Error class for deserialization errors.
# * SerializationError - Error class for serialization errors.
class Base class Base
include Core include Core
include QueueAdapter include QueueAdapter

View file

@ -3,7 +3,7 @@ require 'active_support/tagged_logging'
require 'active_support/logger' require 'active_support/logger'
module ActiveJob module ActiveJob
module Logging module Logging #:nodoc:
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do

View file

@ -2,12 +2,15 @@ require 'active_job/queue_adapters/inline_adapter'
require 'active_support/core_ext/string/inflections' require 'active_support/core_ext/string/inflections'
module ActiveJob module ActiveJob
module QueueAdapter module QueueAdapter #:nodoc:
extend ActiveSupport::Concern extend ActiveSupport::Concern
module ClassMethods module ClassMethods
mattr_reader(:queue_adapter) { ActiveJob::QueueAdapters::InlineAdapter } mattr_reader(:queue_adapter) { ActiveJob::QueueAdapters::InlineAdapter }
# Specify the backend queue provider. The default queue adapter
# is the :inline queue. See QueueAdapters for more
# information.
def queue_adapter=(name_or_adapter) def queue_adapter=(name_or_adapter)
@@queue_adapter = \ @@queue_adapter = \
case name_or_adapter case name_or_adapter
@ -26,4 +29,4 @@ module ActiveJob
end end
end end
end end
end end

View file

@ -6,6 +6,15 @@ module ActiveJob
mattr_accessor(:queue_name_prefix) mattr_accessor(:queue_name_prefix)
mattr_accessor(:default_queue_name) { "default" } mattr_accessor(:default_queue_name) { "default" }
# Specifies the name of the queue to process the job on.
#
# class PublishToFeedJob < ActiveJob::Base
# queue_as :feeds
#
# def perform(post)
# post.to_feed!
# end
# end
def queue_as(part_name=nil, &block) def queue_as(part_name=nil, &block)
if block_given? if block_given?
self.queue_name = block self.queue_name = block

View file

@ -753,7 +753,7 @@ Please refer to the [Changelog][active-support] for detailed changes.
* Introduced new configuration option `active_support.test_order` for * Introduced new configuration option `active_support.test_order` for
specifying the order test cases are executed. This option currently defaults specifying the order test cases are executed. This option currently defaults
to `:sorted` but will be changed to `:random` in Rails 5.0. to `:sorted` but will be changed to `:random` in Rails 5.0.
([Commit](TODO: fill me in)) ([Commit](https://github.com/rails/rails/commit/53e877f7d9291b2bf0b8c425f9e32ef35829f35b))
* The `travel_to` test helper now truncates the `usec` component to 0. * The `travel_to` test helper now truncates the `usec` component to 0.
([Commit](https://github.com/rails/rails/commit/9f6e82ee4783e491c20f5244a613fdeb4024beb5)) ([Commit](https://github.com/rails/rails/commit/9f6e82ee4783e491c20f5244a613fdeb4024beb5))