File tree Expand file tree Collapse file tree 3 files changed +22
-2
lines changed
src/Illuminate/Foundation/Bus Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,14 @@ public static function dispatchAfterResponse(...$arguments)
87
87
return self ::dispatch (...$ arguments )->afterResponse ();
88
88
}
89
89
90
+ /**
91
+ * Defer dispatching a command to its appropriate handler.
92
+ */
93
+ public static function dispatchDefer (...$ arguments )
94
+ {
95
+ return self ::dispatch (...$ arguments )->defer ();
96
+ }
97
+
90
98
/**
91
99
* Set the jobs that should run if this job is successful.
92
100
*
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ class PendingDispatch
28
28
protected $ afterResponse = false ;
29
29
30
30
/**
31
- * Indicates if the job should be dispatched to the queue after the current request .
31
+ * Indicates if the job dispatch should be deferred .
32
32
*
33
33
* @var bool
34
34
*/
@@ -171,7 +171,7 @@ public function afterResponse()
171
171
}
172
172
173
173
/**
174
- * Indicate that the job should be dispatched to the queue after the current request .
174
+ * Indicate that the job dispatch should be deferred .
175
175
*
176
176
* @return $this
177
177
*/
Original file line number Diff line number Diff line change 10
10
use Illuminate \Queue \Events \JobQueued ;
11
11
use Illuminate \Queue \Events \JobQueueing ;
12
12
use Illuminate \Queue \InteractsWithQueue ;
13
+ use Illuminate \Support \Defer \DeferredCallbackCollection ;
13
14
use Illuminate \Support \Facades \Bus ;
14
15
use Illuminate \Support \Facades \Config ;
15
16
use Orchestra \Testbench \Attributes \WithMigration ;
@@ -139,6 +140,17 @@ public function testUniqueJobLockIsReleasedForJobDispatchedAfterResponse()
139
140
$ this ->assertFalse (UniqueJob::$ ran );
140
141
}
141
142
143
+ public function testDispatchDeferDelaysDispatchingUntilDeferredCallbacksAreRun ()
144
+ {
145
+ $ this ->assertFalse (Job::$ ran );
146
+
147
+ Job::dispatchDefer ('test ' );
148
+
149
+ $ this ->assertFalse (Job::$ ran );
150
+ $ this ->app [DeferredCallbackCollection::class]->invoke ();
151
+ $ this ->assertTrue (Job::$ ran );
152
+ }
153
+
142
154
public function testQueueMayBeNullForJobQueueingAndJobQueuedEvent ()
143
155
{
144
156
Config::set ('queue.default ' , 'database ' );
You can’t perform that action at this time.
0 commit comments