@@ -21,7 +21,7 @@ What is Active Job?
21
21
Active Job is a framework for declaring jobs and making them run on a variety
22
22
of queuing backends. These jobs can be everything from regularly scheduled
23
23
clean-ups, to billing charges, to mailings. Anything that can be chopped up
24
- into small units of work and run in parallel, really .
24
+ into small units of work and run in parallel.
25
25
26
26
27
27
The Purpose of Active Job
@@ -196,7 +196,7 @@ Here is a noncomprehensive list of documentation:
196
196
Queues
197
197
------
198
198
199
- Most of the adapters support multiple queues. With Active Job you can schedule
199
+ Most adapters support multiple queues. With Active Job you can schedule
200
200
the job to run on a specific queue using [ ` queue_as ` ] [ ] :
201
201
202
202
``` ruby
268
268
# on your staging environment
269
269
```
270
270
271
- If you want more control on what queue a job will be run you can pass a ` :queue `
272
- option to ` set ` :
273
-
274
- ``` ruby
275
- MyJob .set(queue: :another_queue ).perform_later(record)
276
- ```
277
-
278
271
To control the queue from the job level you can pass a block to ` queue_as ` . The
279
272
block will be executed in the job context (so it can access ` self.arguments ` ),
280
273
and it must return the queue name:
@@ -300,13 +293,67 @@ end
300
293
ProcessVideoJob .perform_later(Video .last)
301
294
```
302
295
296
+ If you want more control on what queue a job will be run you can pass a ` :queue `
297
+ option to ` set ` :
298
+
299
+ ``` ruby
300
+ MyJob .set(queue: :another_queue ).perform_later(record)
301
+ ```
302
+
303
303
NOTE: Make sure your queuing backend "listens" on your queue name. For some
304
304
backends you need to specify the queues to listen to.
305
305
306
306
[ `config.active_job.queue_name_delimiter` ] : configuring.html#config-active-job-queue-name-delimiter
307
307
[ `config.active_job.queue_name_prefix` ] : configuring.html#config-active-job-queue-name-prefix
308
308
[ `queue_as` ] : https://api.rubyonrails.org/classes/ActiveJob/QueueName/ClassMethods.html#method-i-queue_as
309
309
310
+ Priority
311
+ --------------
312
+
313
+ Some adapters support priorities at the job level, where jobs can be prioritised relative to others in the queue or across all queues.
314
+
315
+ You can schedule a job to run with a specific priority using [ ` queue_with_priority ` ] [ ] :
316
+
317
+ ``` ruby
318
+ class GuestsCleanupJob < ApplicationJob
319
+ queue_with_priority 10
320
+ # ...
321
+ end
322
+ ```
323
+
324
+ Note that this will not have any effect with adapters that do not support priorities.
325
+
326
+ Similar to ` queue_as ` , you can also pass a block to ` queue_with_priority ` to be evaluated in the job context:
327
+
328
+ ``` ruby
329
+ class ProcessVideoJob < ApplicationJob
330
+ queue_with_priority do
331
+ video = self .arguments.first
332
+ if video.owner.premium?
333
+ 0
334
+ else
335
+ 10
336
+ end
337
+ end
338
+
339
+ def perform (video )
340
+ # Process video
341
+ end
342
+ end
343
+ ```
344
+
345
+ ``` ruby
346
+ ProcessVideoJob .perform_later(Video .last)
347
+ ```
348
+
349
+ You can also pass a ` :priority ` option to ` set ` :
350
+
351
+ ``` ruby
352
+ MyJob .set(priority: 50 ).perform_later(record)
353
+ ```
354
+
355
+ [ `queue_with_priority` ] : https://api.rubyonrails.org/classes/ActiveJob/QueuePriority/ClassMethods.html#method-i-queue_with_priority
356
+
310
357
Callbacks
311
358
---------
312
359
0 commit comments