File tree 2 files changed +41
-1
lines changed
2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,13 @@ class CallQueuedClosure implements ShouldQueue
22
22
*/
23
23
public $ closure ;
24
24
25
+ /**
26
+ * The name assigned to the job.
27
+ *
28
+ * @var string|null
29
+ */
30
+ public $ name = null ;
31
+
25
32
/**
26
33
* The callbacks that should be executed on failure.
27
34
*
@@ -105,6 +112,21 @@ public function displayName()
105
112
{
106
113
$ reflection = new ReflectionFunction ($ this ->closure ->getClosure ());
107
114
108
- return 'Closure ( ' .basename ($ reflection ->getFileName ()).': ' .$ reflection ->getStartLine ().') ' ;
115
+ $ prefix = is_null ($ this ->name ) ? '' : "{$ this ->name } - " ;
116
+
117
+ return $ prefix .'Closure ( ' .basename ($ reflection ->getFileName ()).': ' .$ reflection ->getStartLine ().') ' ;
118
+ }
119
+
120
+ /**
121
+ * Assign a name to the job.
122
+ *
123
+ * @param string $name
124
+ * @return $this
125
+ */
126
+ public function name ($ name )
127
+ {
128
+ $ this ->name = $ name ;
129
+
130
+ return $ this ;
109
131
}
110
132
}
Original file line number Diff line number Diff line change @@ -166,6 +166,24 @@ public function testQueueMayBeNullForJobQueueingAndJobQueuedEvent()
166
166
$ this ->assertNull ($ events [3 ]->queue );
167
167
}
168
168
169
+ public function testQueuedClosureCanBeNamed ()
170
+ {
171
+ Config::set ('queue.default ' , 'database ' );
172
+ $ events = [];
173
+ $ this ->app ['events ' ]->listen (function (JobQueued $ e ) use (&$ events ) {
174
+ $ events [] = $ e ;
175
+ });
176
+
177
+ dispatch (function () {
178
+ //
179
+ })->name ('custom name ' );
180
+
181
+ $ this ->assertCount (1 , $ events );
182
+ $ this ->assertInstanceOf (JobQueued::class, $ events [0 ]);
183
+ $ this ->assertSame ('custom name ' , $ events [0 ]->job ->name );
184
+ $ this ->assertStringContainsString ('custom name ' , $ events [0 ]->job ->displayName ());
185
+ }
186
+
169
187
public function testCanDisableDispatchingAfterResponse ()
170
188
{
171
189
Job::dispatchAfterResponse ('test ' );
You can’t perform that action at this time.
0 commit comments