diff options
author | Robin Dupret <robin.dupret@gmail.com> | 2015-08-13 16:58:24 +0200 |
---|---|---|
committer | Robin Dupret <robin.dupret@gmail.com> | 2015-08-13 16:58:24 +0200 |
commit | 9d70ec3551563dd9b90abe5d8db07636cb160398 (patch) | |
tree | 6f9c52f722599f47de420f905c6611924de64a2a | |
parent | 812375b2ccfbe5190acd06e9117467a886f91ce6 (diff) | |
parent | 8b2f418972220be8febcf1b68a612c0ae66d9d17 (diff) | |
download | rails-9d70ec3551563dd9b90abe5d8db07636cb160398.tar.gz rails-9d70ec3551563dd9b90abe5d8db07636cb160398.tar.bz2 rails-9d70ec3551563dd9b90abe5d8db07636cb160398.zip |
Merge pull request #21120 from dhiachou/patch-1
How to pass arguments to ActiveJob Jobs [ci skip]
-rw-r--r-- | guides/source/active_job_basics.md | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/guides/source/active_job_basics.md b/guides/source/active_job_basics.md index cb25a4c5f3..e3502d7363 100644 --- a/guides/source/active_job_basics.md +++ b/guides/source/active_job_basics.md @@ -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,21 +85,26 @@ 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) ``` -That's it! +```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 ------------- |