Skip to content

Commit

Permalink
Merge 6e64695 into 2f02f64
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabe Berke-Williams committed Nov 20, 2013
2 parents 2f02f64 + 6e64695 commit 39348e5
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ Call `.delay.method(params)` on any object and it will be processed in the backg
@user.activate!(@device)

# with delayed_job
@user.delay.activate!(@device)
@user.delay.activate!(@device.id)
```

Note that we are passing in the device ID to the delayed version, and not the Device object itself. This is because by the time the job runs, the `@device` object may be out of sync with the actual Device record in the database. Therefore, we pass in the ID and call `device = Device.find(device_id)` in the `User#activate!` method, ensuring that we have an up-to-date version of the device when the job runs.

If a method should always be run in the background, you can call
`#handle_asynchronously` after the method declaration:

Expand Down Expand Up @@ -135,19 +137,19 @@ end

If you ever want to call a `handle_asynchronously`'d method without Delayed Job, for instance while debugging something at the console, just add `_without_delay` to the method name. For instance, if your original method was `foo`, then call `foo_without_delay`.

Rails 3 Mailers
===============
Due to how mailers are implemented in Rails 3, we had to do a little work around to get delayed_job to work.
Mailers in Rails 3 and 4
========================
Due to how mailers are implemented in Rails 3 and 4, we had to do a little work around to get delayed_job to work.

```ruby
# without delayed_job
Notifier.signup(@user).deliver

# with delayed_job
Notifier.delay.signup(@user)
Notifier.delay.signup(@user.id)

# with delayed_job running at a specific time
Notifier.delay(run_at: 5.minutes.from_now).signup(@user)
Notifier.delay(run_at: 5.minutes.from_now).signup(@user.id)
```

Remove the `.deliver` method to make it work. It's not ideal, but it's the best
Expand Down

0 comments on commit 39348e5

Please sign in to comment.