How to run the cron of Schedule:run on Windows

Asked

Viewed 5,527 times

3

I created a cron that should check every minute that the value of the end date is less than the current one... if yes 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 to the kernel

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

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

My doubt is that whenever I run the commands below the 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, it should no longer be run every minute equal set in the kernel?

I found something interesting in this link Schedule page loading through CRON on the line

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

But I couldn’t unroll... I also saw something like creating a . bat, but I didn’t find it functional.

I am in development environment using Windows, someone could give a light?

1 answer

6


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

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

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

In Windows it is possible to use the system Task Scheduler to do this.

Open the task scheduler (or task Scheduler)

Task Scheduler no iniciar

Go to create a new task

Criar nova tarefa

In the General tab set a name for the task and run it even if the user is not logged in (this runs in the background)

nome da tarefa

In the following tab, create a Trigger to be executed every minute indefinitely.

frequência da tarefa

And in the actions tab, create a new action by specifying the php executable, the command artisan schedule run and the directory of your project.

ação da tarefa

After that just give a ok and inform a credential of your user and the Schedule will run as a cron.

  • Thanks friend, that’s exactly it. The only bad side is that every time you open the php prompt and you undo what you’re doing at the moment kkk+ it helped me a lot. Mt thank you!

  • 1

    @Hisoka if I’m not mistaken so it doesn’t happen to have to select the "run when user is logged in or not"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.