Reputation: 265
I'm trying to run a controller function every minute to update the status of my servers but my scheduler is only running once after updating all rows in the table. This is my first time using a task scheduler in Laravel. I tried running it on cmd and it says Running scheduled command: Closure and after all the table is updated the task stops.
//My Controller function to be called
public function updateServerScheduler()
{
$servers = Server::all();
ini_set('max_execution_time', 300);
foreach ($servers as $server)
{
//$server->firewall = @fsockopen($server->ip, 80, $errno, $errstr, 30);
exec("ping -w 60 " . $server->ip, $output, $result);
if($result != 0)
{
$server->status = 0;
$server->latency = "None";
}
else
{
$server->status = 1;
$server->latency = $this->pingDomain($server->ip);
}
$server->last_update = date('Y-m-d H:i:s');
$server->save();
}
}
//My Kernel.php
namespace App\Console;
use App\Http\Controllers\HomeController;
use Server;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
protected $commands = [
//
];
protected function schedule(Schedule $schedule)
{
$schedule->call(function () {
$hc = new HomeController();
$hc->updateServerScheduler();
})->everyMinute();
}
protected function commands()
{
require base_path('routes/console.php');
}
}
Upvotes: 2
Views: 2435
Reputation: 437
Create your command to run schedular and add it in kernel file. ex. $schedule->command('test')->everyMinute();
Upvotes: 0