Skip to content

Commit 5da65f2

Browse files
committed
Add ability to name queued closures
1 parent fc2473f commit 5da65f2

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/Illuminate/Queue/CallQueuedClosure.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ class CallQueuedClosure implements ShouldQueue
3636
*/
3737
public $deleteWhenMissingModels = true;
3838

39+
/**
40+
* Custom name for the job.
41+
*
42+
* @var string|null
43+
*/
44+
public $name = null;
45+
3946
/**
4047
* Create a new job instance.
4148
*
@@ -103,8 +110,26 @@ public function failed($e)
103110
*/
104111
public function displayName()
105112
{
113+
$prefix = '';
106114
$reflection = new ReflectionFunction($this->closure->getClosure());
107115

108-
return 'Closure ('.basename($reflection->getFileName()).':'.$reflection->getStartLine().')';
116+
if (! is_null($this->name)) {
117+
$prefix = "{$this->name} - ";
118+
}
119+
120+
return $prefix.'Closure ('.basename($reflection->getFileName()).':'.$reflection->getStartLine().')';
121+
}
122+
123+
/**
124+
* Set a custom name for the job.
125+
*
126+
* @param string $name
127+
* @return $this
128+
*/
129+
public function name($name)
130+
{
131+
$this->name = $name;
132+
133+
return $this;
109134
}
110135
}

0 commit comments

Comments
 (0)