Last active
September 4, 2022 17:56
-
-
Save ticituc/505dc656bb0cb10d88fbc8857dc19d3e to your computer and use it in GitHub Desktop.
This file contains 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 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