You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add an option to delay job execution when adding to the queue (#52)
* add an option to delay job execution when adding to the queue
* add delay exception test
* fix phpcpd
* tests: make sure the job is added to the queue with the proper delay
@@ -63,6 +63,22 @@ But we can also run the worker like this:
63
63
64
64
This way, worker will consume jobs with the `low` priority and then with `high`. The order set in the config file is override.
65
65
66
+
### Delaying jobs
67
+
68
+
Normally, when we add jobs to a queue, they are run in the order in which we added them to the queue (FIFO - first in, first out).
69
+
Of course, there are also priorities, which we described in the previous section. But what about the scenario where we want to run a job, but not earlier than in 5 minutes?
70
+
71
+
This is where job delay comes into play. We measure the delay in seconds.
72
+
73
+
```php
74
+
// This job will be run not sooner than in 5 minutes
75
+
service('queue')->setDelay(5 * MINUTE)->push('emails', 'email', ['message' => 'Email sent no sooner than 5 minutes from now']);
76
+
```
77
+
78
+
Note that there is no guarantee that the job will run exactly in 5 minutes. If many new jobs are added to the queue (without a delay), it may take a long time before the delayed job is actually executed.
79
+
80
+
We can also combine delayed jobs with priorities.
81
+
66
82
### Running many instances of the same queue
67
83
68
84
As mentioned above, sometimes we may want to have multiple instances of the same command running at the same time. The queue is safe to use in that scenario with all databases as long as you keep the `skipLocked` to `true` in the config file. Only for SQLite3 driver, this setting is not relevant as it provides atomicity without the need for explicit concurrency control.
0 commit comments