Skip to content

Instantly share code, notes, and snippets.

@ticituc
Last active September 4, 2022 17:56
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 ticituc/505dc656bb0cb10d88fbc8857dc19d3e to your computer and use it in GitHub Desktop.
Save ticituc/505dc656bb0cb10d88fbc8857dc19d3e to your computer and use it in GitHub Desktop.
<?php
namespace App\Console\Commands;
use Carbon\Carbon;
use Illuminate\Console\Command;
/**
*
*
*/
class ScheduleWorkCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'schedule:work';
/**
* The console command description.
*
* @var string
*/
protected $description = "Run forever, and any secound try to run schedule commands";
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
$this->info('Schedule worker started successfully.');
while (true) {
if (Carbon::now()->second === 0) {
$this->call('schedule:run');
}
sleep(1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment