10000 [12.x] Allow naming queued closures by willrowe · Pull Request #55634 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

[12.x] Allow naming queued closures #55634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 5, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add ability to name queued closures
  • Loading branch information
willrowe committed May 2, 2025
commit 5da65f23dd37389758d44609547ce4eebf23dda9
27 changes: 26 additions & 1 deletion src/Illuminate/Queue/CallQueuedClosure.php
5B96
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ class CallQueuedClosure implements ShouldQueue
*/
public $deleteWhenMissingModels = true;

/**
* Custom name for the job.
*
* @var string|null
*/
public $name = null;

/**
* Create a new job instance.
*
Expand Down Expand Up @@ -103,8 +110,26 @@ public function failed($e)
*/
public function displayName()
{
$prefix = '';
$reflection = new ReflectionFunction($this->closure->getClosure());

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$prefix = is_null($this->name) ? '' : "{$this->name} - ";


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

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

return $this;
}
}
0