Skip to content
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

[8.x] Create ScheduleListCommand #35574

Merged
merged 2 commits into from Dec 11, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/Illuminate/Console/Scheduling/ScheduleListCommand.php
@@ -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 ?? []);
}
}
12 changes: 12 additions & 0 deletions src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Cache\Console\ClearCommand as CacheClearCommand;
use Illuminate\Cache\Console\ForgetCommand as CacheForgetCommand;
use Illuminate\Console\Scheduling\ScheduleFinishCommand;
use Illuminate\Console\Scheduling\ScheduleListCommand;
use Illuminate\Console\Scheduling\ScheduleRunCommand;
use Illuminate\Console\Scheduling\ScheduleWorkCommand;
use Illuminate\Contracts\Support\DeferrableProvider;
Expand Down Expand Up @@ -117,6 +118,7 @@ class ArtisanServiceProvider extends ServiceProvider implements DeferrableProvid
'ScheduleFinish' => ScheduleFinishCommand::class,
'ScheduleRun' => ScheduleRunCommand::class,
'ScheduleWork' => ScheduleWorkCommand::class,
'ScheduleList' => ScheduleListCommand::class,
'StorageLink' => 'command.storage.link',
'Up' => 'command.up',
'ViewCache' => 'command.view.cache',
Expand Down Expand Up @@ -938,6 +940,16 @@ protected function registerScheduleWorkCommand()
$this->app->singleton(ScheduleWorkCommand::class);
}

/**
* Register the command.
*
* @return void
*/
protected function registerScheduleListCommand()
{
$this->app->singleton(ScheduleListCommand::class);
}

/**
* Register the command.
*
Expand Down