Skip to content

Commit

Permalink
Create ScheduleListCommand.php
Browse files Browse the repository at this point in the history
display a table of all the scheduled commands
  • Loading branch information
browner12 committed Dec 11, 2020
1 parent 2a9919a commit 3e16743
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/Illuminate/Console/Scheduling/ScheduleListCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Illuminate\Console\Scheduling;

use Cron\CronExpression;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;

class ScheduleListCommand extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'schedule:list';

/**
* 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,
(new CronExpression($event->expression))->getPreviousRunDate(Carbon::now()),
(new CronExpression($event->expression))->getNextRunDate(Carbon::now()),
];
}

$this->table([
'Command',
'Interval',
'Description',
'Last Run',
'Next Due',
], $rows ?? []);
}
}

0 comments on commit 3e16743

Please sign in to comment.