Last active
April 19, 2019 18:09
-
-
Save alexrusin/6c75898808f1fa9c5845f0db3c21bac3 to your computer and use it in GitHub Desktop.
Notes for Scheduling Tasks
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
// Console/Kernel.php | |
protected $commands = [ | |
Commands\MasterCommand::class, | |
Commands\CommandOne::class, | |
Commands\CommandTwo::class | |
]; | |
/** | |
* Define the application's command schedule. | |
* | |
* @param \Illuminate\Console\Scheduling\Schedule $schedule | |
* @return void | |
*/ | |
protected function schedule(Schedule $schedule) | |
{ | |
$schedule->command('command-master')->everyMinute(); | |
//$schedule->command('command-one >> /dev/null 2>&1 &')->everyMinute(); | |
//$schedule->command('command-two >> /dev/null 2>&1 &')->everyMinute(); | |
} | |
//MasterCommand.php | |
<?php | |
namespace App\Console\Commands; | |
use Illuminate\Console\Command; | |
class MasterCommand extends Command | |
{ | |
/** | |
* The name and signature of the console command. | |
* | |
* @var string | |
*/ | |
protected $signature = 'command-master'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Command master'; | |
/** | |
* Execute the console command. | |
* | |
* @return mixed | |
*/ | |
public function handle() | |
{ | |
set_time_limit(300); | |
\Log::info('Started command master'); | |
\Log::info('Command master spins up command one'); | |
exec('php '. base_path('artisan command-one ') . '>> /dev/null 2>&1 &'); | |
\Log::info('Command master spins up command two'); | |
exec('php '. base_path('artisan command-two ') . '>> /dev/null 2>&1 &'); | |
\Log::info('Command master is done'); | |
} | |
} | |
//CommandOne.php | |
<?php | |
namespace App\Console\Commands; | |
use Illuminate\Console\Command; | |
class CommandOne extends Command | |
{ | |
/** | |
* The name and signature of the console command. | |
* | |
* @var string | |
*/ | |
protected $signature = 'command-one'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Command one'; | |
/** | |
* Execute the console command. | |
* | |
* @return mixed | |
*/ | |
public function handle() | |
{ | |
set_time_limit(300); | |
\Log::info('Started command one'); | |
\Log::info('Command one goes to sleep for 2 minutes'); | |
sleep(120); | |
\Log::info('Command one woke up'); | |
\Log::info('Command one is done'); | |
} | |
} | |
//CommandTwo.php | |
<?php | |
namespace App\Console\Commands; | |
use Illuminate\Console\Command; | |
class CommandTwo extends Command | |
{ | |
/** | |
* The name and signature of the console command. | |
* | |
* @var string | |
*/ | |
protected $signature = 'command-two'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Command two'; | |
/** | |
* Execute the console command. | |
* | |
* @return mixed | |
*/ | |
public function handle() | |
{ | |
set_time_limit(300); | |
\Log::info('Started command two'); | |
\Log::info('Command two goes to sleep for 30 seconds'); | |
sleep(30); | |
\Log::info('Command two woke up'); | |
\Log::info('Command two is done'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment