How to run schedule: cron cron in Windows

2

I created a cron that should check every minute if the value of the end date is smaller than the current one ... if yes it should update the status field of this table.

class SetStatus extends Command
{

protected $signature = 'SetStatus:cron';

public function handle()
{
    //o código ta uma zona apenas pra teste...
    $sql = 'select id from promotions where dt_end < NOW()';
    $dados = \DB::select($sql);
    foreach($dados as $i)
    {
        $updateStatus = 'update promotions set status = "inativo" where id IN ('.$i->id.')';
        $return = \DB::update($updateStatus);
    }
    var_dump($return);
}

}

and added in the kernel

 protected $commands = [
    Commands\SetStatus::class,
];

protected function schedule(Schedule $schedule)
{
    $schedule->command('SetStatus:cron')->everyMinute();
}

My question is that every time I run the commands below, CRON runs successfully, but stops there. The next minute it does not run again.

php artisan SetStatus:cron
php c:/projetos/marcelo/painel/artisan schedule:run

After running these commands above, should not it be run every time I set it in the kernel?

I found something interesting in this link Schedule page load through CRON in line

# crontab -e 00 * * * * /usr/local/bin/php /home/pedrodelfino/meu-script.php

But I could not unroll ... I also saw something like creating a .bat, but I did not find it functional.

I'm in the development environment using Windows, could anyone give a light?

    
asked by anonymous 28.12.2017 / 02:26

1 answer

1

On Linux, it is recommended to add an entry in cron as suggested by the Laravel documentation .

* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1

This cron will run the schedule:run command every minute.

In the Windows environment, you can use the System Scheduler to do this.

Open the task scheduler

Gocreateanewtask

Inthegeneraltabdefineanameforthetaskandtoexecuteiteveniftheuserisnotloggedin(thisrunsinthebackground)

Onthenexttab,createatriggertoruneveryminuteindefinitely.

Andintheactionstab,createanewactionspecifyingthephpexecutable,theartisanscheduleruncommand,andthedirectoryofyourproject.

After that, just give an ok and inform a user credential and the schedule will run as a cron .

    
28.12.2017 / 21:04