2017-07-09 13:49:52 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 09:40:03 -04:00
|
|
|
|
2017-06-30 01:17:57 -04:00
|
|
|
require_relative "core"
|
|
|
|
require_relative "queue_adapter"
|
|
|
|
require_relative "queue_name"
|
|
|
|
require_relative "queue_priority"
|
|
|
|
require_relative "enqueuing"
|
|
|
|
require_relative "execution"
|
|
|
|
require_relative "callbacks"
|
|
|
|
require_relative "exceptions"
|
|
|
|
require_relative "logging"
|
|
|
|
require_relative "translation"
|
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
|
|
|
#
|
2015-11-08 20:38:13 -05:00
|
|
|
# To enqueue a job to be performed as soon as 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
|
2015-03-18 05:48:26 -04:00
|
|
|
include QueuePriority
|
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
|
2016-07-29 16:54:55 -04:00
|
|
|
include Exceptions
|
2014-05-22 13:33:23 -04:00
|
|
|
include Logging
|
2015-07-07 15:52:28 -04:00
|
|
|
include Translation
|
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
|