mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
[ci skip] How to pass arguments to ActiveJob Jobs
A section explaining how to pass arguments to Jobs has been added. [ci skip] How to pass arguments to ActiveJob Jobs Removed the "how to pass arguments" from what you will know section [ci skip] improving Enqueue Job section Using GuestsCleanupJob rather than MyJob for coherence. [ci skip] Passing args section merged with enqueuing jobs Passing args is now explained through examples withing Enqueuing the Jobs section [ci skip] Unnecessary example removed [ci skip] Typo fixed (missing as)
This commit is contained in:
parent
7a3ca69959
commit
8b2f418972
1 changed files with 12 additions and 5 deletions
|
@ -70,12 +70,14 @@ Here's what a job looks like:
|
|||
class GuestsCleanupJob < ActiveJob::Base
|
||||
queue_as :default
|
||||
|
||||
def perform(*args)
|
||||
def perform(*guests)
|
||||
# Do something later
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
Note that you can define `perform` with as many arguments as you want.
|
||||
|
||||
### Enqueue the Job
|
||||
|
||||
Enqueue a job like so:
|
||||
|
@ -83,22 +85,27 @@ Enqueue a job like so:
|
|||
```ruby
|
||||
# Enqueue a job to be performed as soon the queuing system is
|
||||
# free.
|
||||
MyJob.perform_later record
|
||||
GuestsCleanupJob.perform_later guest
|
||||
```
|
||||
|
||||
```ruby
|
||||
# Enqueue a job to be performed tomorrow at noon.
|
||||
MyJob.set(wait_until: Date.tomorrow.noon).perform_later(record)
|
||||
GuestsCleanupJob.set(wait_until: Date.tomorrow.noon).perform_later(guest)
|
||||
```
|
||||
|
||||
```ruby
|
||||
# Enqueue a job to be performed 1 week from now.
|
||||
MyJob.set(wait: 1.week).perform_later(record)
|
||||
GuestsCleanupJob.set(wait: 1.week).perform_later(guest)
|
||||
```
|
||||
|
||||
```ruby
|
||||
# `perform_now` and `perform_later` will call `perform` under the hood so
|
||||
# you can pass as many arguments as defined in the latter.
|
||||
GuestsCleanupJob.perform_later(guest1, guest2, filter: 'some_filter')
|
||||
```
|
||||
|
||||
That's it!
|
||||
|
||||
|
||||
Job Execution
|
||||
-------------
|
||||
|
||||
|
|
Loading…
Reference in a new issue