2014-08-25 10:34:50 -04:00
|
|
|
require 'active_job/core'
|
2014-05-19 04:55:57 -04:00
|
|
|
require 'active_job/queue_adapter'
|
2014-05-19 05:04:23 -04:00
|
|
|
require 'active_job/queue_name'
|
2014-05-19 06:06:09 -04:00
|
|
|
require 'active_job/enqueuing'
|
2014-05-22 14:37:06 -04:00
|
|
|
require 'active_job/execution'
|
2014-05-22 13:33:23 -04:00
|
|
|
require 'active_job/callbacks'
|
2014-05-22 16:38:01 -04:00
|
|
|
require 'active_job/logging'
|
2014-05-18 06:32:22 -04:00
|
|
|
|
2014-09-26 13:10:06 -04:00
|
|
|
module ActiveJob #:nodoc:
|
|
|
|
# = Active Job
|
|
|
|
#
|
2014-10-20 02:59:36 -04:00
|
|
|
# Active Job objects can be configured to work with different backend
|
2014-09-26 13:10:06 -04:00
|
|
|
# queuing frameworks. To specify a queue adapter to use:
|
|
|
|
#
|
|
|
|
# ActiveJob::Base.queue_adapter = :inline
|
|
|
|
#
|
|
|
|
# A list of supported adapters can be found in QueueAdapters.
|
|
|
|
#
|
2014-10-20 02:59:36 -04:00
|
|
|
# Active Job objects can be defined by creating a class that inherits
|
2014-09-26 13:10:06 -04:00
|
|
|
# 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
|
2014-11-10 08:56:07 -05:00
|
|
|
# ID. More information can be found in Arguments.
|
2014-09-26 13:10:06 -04:00
|
|
|
#
|
2014-10-20 15:24:03 -04:00
|
|
|
# To enqueue a job to be performed as soon the queueing system is free:
|
2014-09-26 13:10:06 -04:00
|
|
|
#
|
|
|
|
# ProcessPhotoJob.perform_later(photo)
|
|
|
|
#
|
2014-10-20 15:24:03 -04:00
|
|
|
# To enqueue a job to be processed at some point in the future:
|
2014-09-26 13:10:06 -04:00
|
|
|
#
|
|
|
|
# ProcessPhotoJob.set(wait_until: Date.tomorrow.noon).perform_later(photo)
|
|
|
|
#
|
|
|
|
# More information can be found in ActiveJob::Core::ClassMethods#set
|
|
|
|
#
|
2014-10-20 15:24:03 -04:00
|
|
|
# A job can also be processed immediately without sending to the queue:
|
2014-10-19 14:56:38 -04:00
|
|
|
#
|
|
|
|
# ProcessPhotoJob.perform_now(photo)
|
|
|
|
#
|
2014-09-26 13:10:06 -04:00
|
|
|
# == Exceptions
|
|
|
|
#
|
|
|
|
# * DeserializationError - Error class for deserialization errors.
|
|
|
|
# * SerializationError - Error class for serialization errors.
|
2014-05-18 05:44:28 -04:00
|
|
|
class Base
|
2014-08-25 10:34:50 -04:00
|
|
|
include Core
|
2014-08-26 16:08:49 -04:00
|
|
|
include QueueAdapter
|
2014-06-09 12:49:14 -04:00
|
|
|
include QueueName
|
2014-05-22 13:33:23 -04:00
|
|
|
include Enqueuing
|
2014-05-22 14:37:06 -04:00
|
|
|
include Execution
|
2014-05-22 13:33:23 -04:00
|
|
|
include Callbacks
|
|
|
|
include Logging
|
2014-05-21 17:10:17 -04:00
|
|
|
|
|
|
|
ActiveSupport.run_load_hooks(:active_job, self)
|
2014-05-18 05:44:28 -04:00
|
|
|
end
|
2014-05-20 07:41:14 -04:00
|
|
|
end
|