Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/Illuminate/Queue/CallQueuedClosure.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ class CallQueuedClosure implements ShouldQueue
*/
public $closure;

/**
* The name assigned to the job.
*
* @var string|null
*/
public $name = null;

/**
* The callbacks that should be executed on failure.
*
Expand Down Expand Up @@ -105,6 +112,21 @@ public function displayName()
{
$reflection = new ReflectionFunction($this->closure->getClosure());

return 'Closure ('.basename($reflection->getFileName()).':'.$reflection->getStartLine().')';
$prefix = is_null($this->name) ? '' : "{$this->name} - ";

return $prefix.'Closure ('.basename($reflection->getFileName()).':'.$reflection->getStartLine().')';
}

/**
* Assign a name to the job.
*
* @param string $name
* @return $this
*/
public function name($name)
{
$this->name = $name;

return $this;
}
}
18 changes: 18 additions & 0 deletions tests/Integration/Queue/JobDispatchingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,24 @@ public function testQueueMayBeNullForJobQueueingAndJobQueuedEvent()
$this->assertNull($events[3]->queue);
}

public function testQueuedClosureCanBeNamed()
{
Config::set('queue.default', 'database');
$events = [];
$this->app['events']->listen(function (JobQueued $e) use (&$events) {
$events[] = $e;
});

dispatch(function () {
//
})->name('custom name');

$this->assertCount(1, $events);
$this->assertInstanceOf(JobQueued::class, $events[0]);
$this->assertSame('custom name', $events[0]->job->name);
$this->assertStringContainsString('custom name', $events[0]->job->displayName());
}

public function testCanDisableDispatchingAfterResponse()
{
Job::dispatchAfterResponse('test');
Expand Down