Storm Spirit
Storm Spirit

Reputation: 1520

Laravel Cron Job Run only once in windows 10

I've created a Task Scheduling from Laravel Documentation: https://laravel.com/docs/5.7/scheduling

I put it everyMinute() and it only execute once when I use that command and not executing every minute. I used cronhub.io to monitor it and the result was the one I execute the command.

enter image description here

This is the command I execute:

$ php artisan schedule:run
Running scheduled command: "E:\Laragon\bin\php\php-7.2.11-Win32-VC15-x64\php.exe" "artisan" update:weather > "NUL" 2>&1

App\Console\Kernel.php

<?php
...
class Kernel extends ConsoleKernel
{
...
protected function schedule(Schedule $schedule)
    {          $schedule->command('update:weather')->everyMinute()->thenPing("https://cronhub.io/ping/ce3d19a0-6c01-11e9-8ce3-9b563ae1be45");
    }

And on my App\Console\Commands\UpdateWeatherIcon.php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Enums\WeatherIcon;
use App\Weather;

class UpdateWeatherIcon extends Command
{
    protected $signature = 'update:weather';
    protected $description = 'Update Weather Icon every end of day';

    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
        $weather = new WeatherIcon();

        $current_weather = Weather::find(1);
        $current_weather->current_weather = $weather->getRandomValue();
        $current_weather->updated_at = \Carbon\Carbon::now();
        $current_weather->save();
    }
}

Does it only run once in windows 10? cause this is my first time using cron jobs.

Upvotes: 0

Views: 2984

Answers (1)

Sajad eskandarian
Sajad eskandarian

Reputation: 11

you most run this command

$ php artisan schedule:work

if you set cronjob on shared hosting you must add this command

cd /home/admin/domains/yourdomain.com/projectfolder && php artisan schedule:run >> /dev/null 2>&1 

Upvotes: 1

Related Questions