Skip to content

Instantly share code, notes, and snippets.

@simonhamp
Created January 6, 2021 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonhamp/365c1f5375980968431e0cec68a73854 to your computer and use it in GitHub Desktop.
Save simonhamp/365c1f5375980968431e0cec68a73854 to your computer and use it in GitHub Desktop.
Laravel: Back-port the schedule:list command
<?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