Felix
Felix

Reputation: 2661

Task scheduler in laravel homestead

I'm trying to get scheduled tasks to work in homestead.

First I created a command in called "randomUserCreatesubmission".

protected $signature = 'command:randomusercreatesubmission';

This command works just fine.

I then added it to a schedule in Kernel.php

protected function schedule(Schedule $schedule)
{
    $schedule->command('disposable:update')->weekly();
    $schedule->command('command:randomusercreatesubmission')->everyMinute();
}

Then, after SSHing into homestead, I run the command

php artisan schedule:run

This returns the following:

Running scheduled command: '/usr/bin/php7.4' 'artisan' command:randomusercreatesubmission > '/dev/null' 2>&1

and it will run the "randomUserCreatesubmission" command once, immediately. However, I want it to run every minute, and it does not do that.

Why is this happening?

Upvotes: 1

Views: 747

Answers (2)

mmabdelgawad
mmabdelgawad

Reputation: 2545

You need to setup a cron job. You can run in your terminal

crontab -e

then add to the end of your crontab

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

and this command will run every minute.

Upvotes: 3

Matt Komarnicki
Matt Komarnicki

Reputation: 5422

Don't forget to start scheduler by adding below statement into crontab -e

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

Familiarize yourself with the official Laravel Scheduler documentation.

Upvotes: 0

Related Questions