Created
January 6, 2021 13:12
-
-
Save simonhamp/365c1f5375980968431e0cec68a73854 to your computer and use it in GitHub Desktop.
Laravel: Back-port the schedule:list command
This file contains hidden or 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
<?php | |
namespace App\Console\Commands; | |
use Cron\CronExpression; | |
use Illuminate\Console\Command; | |
use Illuminate\Support\Carbon; | |
use Illuminate\Console\Scheduling\Schedule; | |
class ScheduleListCommand extends Command | |
{ | |
/** | |
* The console command name. | |
* | |
* @var string | |
*/ | |
protected $signature = 'schedule:list {--timezone= : The timezone that times should be displayed in}'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'List the scheduled commands'; | |
/** | |
* Execute the console command. | |
* | |
* @param \Illuminate\Console\Scheduling\Schedule $schedule | |
* @return void | |
* @throws \Exception | |
*/ | |
public function handle(Schedule $schedule) | |
{ | |
foreach ($schedule->events() as $event) { | |
$rows[] = [ | |
$event->command, | |
$event->expression, | |
$event->description, | |
(CronExpression::factory($event->expression)) | |
->getNextRunDate(Carbon::now()) | |
->setTimezone($this->option('timezone', config('app.timezone'))), | |
]; | |
} | |
$this->table([ | |
'Command', | |
'Interval', | |
'Description', | |
'Next Due', | |
], $rows ?? []); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment