Skip to content

Commit

Permalink
Merge pull request #16583 from JuanitoFatas/doc/patch-1
Browse files Browse the repository at this point in the history
[ci skip] Format pass of Active Job Basics guide.
  • Loading branch information
rafaelfranca committed Aug 20, 2014
2 parents 500deec + 5833163 commit 3553816
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions guides/source/active_job_basics.md
Expand Up @@ -13,6 +13,7 @@ After reading this guide, you will know:

--------------------------------------------------------------------------------


Introduction
------------

Expand Down Expand Up @@ -40,7 +41,7 @@ This section will provide a step-by-step guide to creating a job and enqueue it.
### Create the Job

Active Job provides a Rails generator to create jobs. The following will create a
job in app/jobs:
job in `app/jobs`:

```bash
$ bin/rails generate job guests_cleanup
Expand All @@ -58,7 +59,7 @@ As you can see, you can generate jobs just like you use other generators with
Rails.

If you don't want to use a generator, you could create your own file inside of
app/jobs, just make sure that it inherits from `ActiveJob::Base`.
`app/jobs`, just make sure that it inherits from `ActiveJob::Base`.

Here's how a job looks like:

Expand Down Expand Up @@ -135,11 +136,12 @@ You can easy change your adapter:
YourApp::Application.config.active_job.queue_adapter = :sidekiq
```


Queues
------

Most of the adapters supports multiple queues. With Active Job you can schedule the job
to run on a specific queue:
Most of the adapters supports multiple queues. With Active Job you can schedule
the job to run on a specific queue:

```ruby
class GuestsCleanupJob < ActiveJob::Base
Expand All @@ -155,17 +157,17 @@ you need to specify the queues to listen to.
Callbacks
---------

Active Job provides hooks during the lifecycle of a job. Callbacks allows you to trigger
logic during the lifecycle of a job.
Active Job provides hooks during the lifecycle of a job. Callbacks allows you to
trigger logic during the lifecycle of a job.

### Available callbacks

* before_enqueue
* around_enqueue
* after_enqueue
* before_perform
* around_perform
* after_perform
* `before_enqueue`
* `around_enqueue`
* `after_enqueue`
* `before_perform`
* `around_perform`
* `after_perform`

### Usage

Expand All @@ -189,8 +191,10 @@ class GuestsCleanupJob < ActiveJob::Base
end
```


ActionMailer
------------

One of the most common jobs in a modern web application is sending emails outside
of the request-response cycle, so the user doesn't have to wait on it. Active Job
is integrated with Action Mailer so you can easily send emails async:
Expand All @@ -203,11 +207,12 @@ UserMailer.welcome(@user).deliver
UserMailer.welcome(@user).deliver_later
```


GlobalID
--------
Active Job supports GlobalID 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:
Active Job supports GlobalID 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:

```ruby
class TrashableCleanupJob
Expand All @@ -228,12 +233,13 @@ class TrashableCleanupJob
end
```

This works with any class that mixes in ActiveModel::GlobalIdentification, which
This works with any class that mixes in `ActiveModel::GlobalIdentification`, which
by default has been mixed into Active Model classes.


Exceptions
----------

Active Job provides a way to catch exceptions raised during the execution of the
job:

Expand Down

0 comments on commit 3553816

Please sign in to comment.