-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add artisan command
laravel-utils:dispatch-job
- Loading branch information
Showing
3 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace MLL\LaravelUtils\Queue; | ||
|
||
use Illuminate\Console\Command; | ||
|
||
final class DispatchJob extends Command | ||
{ | ||
protected $signature = 'laravel-utils:dispatch-job {class}'; | ||
|
||
protected $description = 'Dispatch a job with the given class'; | ||
|
||
public function handle(): void | ||
{ | ||
$class = $this->argument('class'); | ||
if (! is_string($class)) { | ||
$notString = gettype($class); | ||
throw new \Exception("Expected argument 'class' to be string, got {$notString}."); | ||
} | ||
if (! class_exists($class)) { | ||
throw new \Exception("Job class {$class} does not exist."); | ||
} | ||
|
||
if (! method_exists($class, 'dispatch')) { | ||
throw new \Exception("Job class {$class} does not have a method 'dispatch'."); | ||
} | ||
$class::dispatch(); | ||
} | ||
} |