aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@basecamp.com>2014-09-04 18:50:28 -0700
committerDavid Heinemeier Hansson <david@basecamp.com>2014-09-04 18:50:28 -0700
commit4d8523c382736c18c11a072a1ab2a892cc1a6c1f (patch)
tree2b68238b06a53b0a02a6eaa9c63bf120f197efb5 /guides
parent312e4cda78e04d04308a3b9bee822f540d11103f (diff)
parent15ddf60e05f5995b1aaf8d8cecfa2354005cc035 (diff)
downloadrails-4d8523c382736c18c11a072a1ab2a892cc1a6c1f.tar.gz
rails-4d8523c382736c18c11a072a1ab2a892cc1a6c1f.tar.bz2
rails-4d8523c382736c18c11a072a1ab2a892cc1a6c1f.zip
Merge pull request #16699 from cristianbica/aj-refactor-queueing
Active Job partial refactor
Diffstat (limited to 'guides')
-rw-r--r--guides/source/active_job_basics.md44
1 files changed, 38 insertions, 6 deletions
diff --git a/guides/source/active_job_basics.md b/guides/source/active_job_basics.md
index 2c6e79a5b0..7b3081993d 100644
--- a/guides/source/active_job_basics.md
+++ b/guides/source/active_job_basics.md
@@ -78,15 +78,15 @@ end
Enqueue a job like so:
```ruby
-MyJob.enqueue record # Enqueue a job to be performed as soon the queueing system is free.
+MyJob.perform_later record # Enqueue a job to be performed as soon the queueing system is free.
```
```ruby
-MyJob.enqueue_at Date.tomorrow.noon, record # Enqueue a job to be performed tomorrow at noon.
+MyJob.set(wait_until: Date.tomorrow.noon).perform_later(record) # Enqueue a job to be performed tomorrow at noon.
```
```ruby
-MyJob.enqueue_in 1.week, record # Enqueue a job to be performed 1 week from now.
+MyJob.set(wait: 1.week).perform_later(record) # Enqueue a job to be performed 1 week from now.
```
That's it!
@@ -155,7 +155,7 @@ class GuestsCleanupJob < ActiveJob::Base
end
```
-Also you can prefix the queue name for all your jobs using
+You can prefix the queue name for all your jobs using
`config.active_job.queue_name_prefix` in `application.rb`:
```ruby
@@ -172,10 +172,42 @@ class GuestsCleanupJob < ActiveJob::Base
#....
end
-# Now your job will run on queue production_low_priority on your production
-# environment and on beta_low_priority on your beta environment
+# Now your job will run on queue production_low_priority on your
+# production environment and on beta_low_priority on your beta
+# environment
```
+If you want more control on what queue a job will be run you can pass a :queue
+option to #set:
+
+```ruby
+MyJob.set(queue: :another_queue).perform_later(record)
+```
+
+To control the queue from the job level you can pass a block to queue_as. The
+block will be executed in the job context (so you can access self.arguments)
+and you must return the queue name:
+
+```ruby
+class ProcessVideoJob < ActiveJob::Base
+ queue_as do
+ video = self.arguments.first
+ if video.owner.premium?
+ :premium_videojobs
+ else
+ :videojobs
+ end
+ end
+
+ def perform(video)
+ # do process video
+ end
+end
+
+ProcessVideoJob.perform_later(Video.last)
+```
+
+
NOTE: Make sure your queueing backend "listens" on your queue name. For some
backends you need to specify the queues to listen to.