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

Merge pull request #40680 from jonathanhefner/guide-active_job_basics-link-api

Link to API docs in Active Job Basics guide [ci-skip]
This commit is contained in:
Jonathan Hefner 2020-11-27 11:18:25 -06:00 committed by GitHub
commit c4bbdb1c60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -81,7 +81,7 @@ Note that you can define `perform` with as many arguments as you want.
### Enqueue the Job ### Enqueue the Job
Enqueue a job like so: Enqueue a job using [`perform_later`][] and, optionally, [`set`][]. Like so:
```ruby ```ruby
# Enqueue a job to be performed as soon as the queuing system is # Enqueue a job to be performed as soon as the queuing system is
@ -107,6 +107,9 @@ GuestsCleanupJob.perform_later(guest1, guest2, filter: 'some_filter')
That's it! That's it!
[`perform_later`]: https://api.rubyonrails.org/classes/ActiveJob/Enqueuing/ClassMethods.html#method-i-perform_later
[`set`]: https://api.rubyonrails.org/classes/ActiveJob/Core/ClassMethods.html#method-i-set
Job Execution Job Execution
------------- -------------
@ -121,7 +124,9 @@ production apps will need to pick a persistent backend.
Active Job has built-in adapters for multiple queuing backends (Sidekiq, Active Job has built-in adapters for multiple queuing backends (Sidekiq,
Resque, Delayed Job, and others). To get an up-to-date list of the adapters Resque, Delayed Job, and others). To get an up-to-date list of the adapters
see the API Documentation for [ActiveJob::QueueAdapters](https://api.rubyonrails.org/classes/ActiveJob/QueueAdapters.html). see the API Documentation for [`ActiveJob::QueueAdapters`][].
[`ActiveJob::QueueAdapters`]: https://api.rubyonrails.org/classes/ActiveJob/QueueAdapters.html
### Setting the Backend ### Setting the Backend
@ -172,7 +177,7 @@ Queues
------ ------
Most of the adapters support multiple queues. With Active Job you can schedule Most of the adapters support multiple queues. With Active Job you can schedule
the job to run on a specific queue: the job to run on a specific queue using [`queue_as`][]:
```ruby ```ruby
class GuestsCleanupJob < ApplicationJob class GuestsCleanupJob < ApplicationJob
@ -272,6 +277,7 @@ ProcessVideoJob.perform_later(Video.last)
NOTE: Make sure your queuing backend "listens" on your queue name. For some NOTE: Make sure your queuing backend "listens" on your queue name. For some
backends you need to specify the queues to listen to. backends you need to specify the queues to listen to.
[`queue_as`]: https://api.rubyonrails.org/classes/ActiveJob/QueueName/ClassMethods.html#method-i-queue_as
Callbacks Callbacks
--------- ---------
@ -311,13 +317,19 @@ end
### Available callbacks ### Available callbacks
* `before_enqueue` * [`before_enqueue`][]
* `around_enqueue` * [`around_enqueue`][]
* `after_enqueue` * [`after_enqueue`][]
* `before_perform` * [`before_perform`][]
* `around_perform` * [`around_perform`][]
* `after_perform` * [`after_perform`][]
[`before_enqueue`]: https://api.rubyonrails.org/classes/ActiveJob/Callbacks/ClassMethods.html#method-i-before_enqueue
[`around_enqueue`]: https://api.rubyonrails.org/classes/ActiveJob/Callbacks/ClassMethods.html#method-i-around_enqueue
[`after_enqueue`]: https://api.rubyonrails.org/classes/ActiveJob/Callbacks/ClassMethods.html#method-i-after_enqueue
[`before_perform`]: https://api.rubyonrails.org/classes/ActiveJob/Callbacks/ClassMethods.html#method-i-before_perform
[`around_perform`]: https://api.rubyonrails.org/classes/ActiveJob/Callbacks/ClassMethods.html#method-i-around_perform
[`after_perform`]: https://api.rubyonrails.org/classes/ActiveJob/Callbacks/ClassMethods.html#method-i-after_perform
Action Mailer Action Mailer
------------ ------------
@ -437,8 +449,8 @@ Rails.application.config.active_job.custom_serializers << MoneySerializer
Exceptions Exceptions
---------- ----------
Active Job provides a way to catch exceptions raised during the execution of the Exceptions raised during the execution of the job can be handled with
job: [`rescue_from`][]:
```ruby ```ruby
class GuestsCleanupJob < ApplicationJob class GuestsCleanupJob < ApplicationJob
@ -456,12 +468,14 @@ end
If the exception is not rescued within the job, e.g. as shown above, then the job is referred to as "failed". If the exception is not rescued within the job, e.g. as shown above, then the job is referred to as "failed".
[`rescue_from`]: https://api.rubyonrails.org/classes/ActiveSupport/Rescuable/ClassMethods.html#method-i-rescue_from
### Retrying or Discarding failed jobs ### Retrying or Discarding failed jobs
A failed job will not be retried, unless configured otherwise. A failed job will not be retried, unless configured otherwise.
It's also possible to retry or discard a job if an exception is raised during execution. It's possible to retry or discard a failed job by using [`retry_on`] or
For example: [`discard_on`], respectively. For example:
```ruby ```ruby
class RemoteServiceJob < ApplicationJob class RemoteServiceJob < ApplicationJob
@ -475,16 +489,19 @@ class RemoteServiceJob < ApplicationJob
end end
``` ```
To get more details see the API Documentation for [ActiveJob::Exceptions](https://api.rubyonrails.org/classes/ActiveJob/Exceptions/ClassMethods.html). [`discard_on`]: https://api.rubyonrails.org/classes/ActiveJob/Exceptions/ClassMethods.html#method-i-discard_on
[`retry_on`]: https://api.rubyonrails.org/classes/ActiveJob/Exceptions/ClassMethods.html#method-i-retry_on
### Deserialization ### Deserialization
GlobalID allows serializing full Active Record objects passed to `#perform`. GlobalID allows serializing full Active Record objects passed to `#perform`.
If a passed record is deleted after the job is enqueued but before the `#perform` If a passed record is deleted after the job is enqueued but before the `#perform`
method is called Active Job will raise an `ActiveJob::DeserializationError` method is called Active Job will raise an [`ActiveJob::DeserializationError`][]
exception. exception.
[`ActiveJob::DeserializationError`]: https://api.rubyonrails.org/classes/ActiveJob/DeserializationError.html
Job Testing Job Testing
-------------- --------------