0

I'm trying to set up a scheduling task that can run every five minutes, but it only works 1 time, after the first five minutes, the other five minutes dont do the function correctly.

//depresiasicounter.php

protected $signature = 'updates:depresiasicounter';

public function handle()
{
    $aktivatb = Aktivatb::where('id','1')->first();
        $aktivatb->nilai= $aktivatb->nilai-$aktivatb->depresiasi;
        $aktivatb->total_depresiasi = $aktivatb->total_depresiasi+$aktivatb->depresiasi;
    $aktivatb->save();
}

//kernel.php

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


protected function schedule(Schedule $schedule)
{
    $schedule->commands('updates:depresiasicounter')->everyFiveMinutes();
}

I expect it can be work until the value of $aktivatb->nilai to 0, but it only works 1 time

Rizky Pratama
  • 13
  • 1
  • 5

2 Answers2

1

A Scheduled task is basically the system is running a command

php /project-path/artisan schedule:run

every given amount of time.

In Linux environment, people use cron to handle this by creating a crontab

* * * * * php /project-path/artisan schedule:run

Those asterisk signs in front of the command indicates the interval of the command.

In Windows environment, you can refer to the following answer.

Or you can setup a virtual machine and run the cron job inside the machine.

Cloud Soh Jun Fu
  • 1,456
  • 9
  • 12
0

You need to setup cron so it could run the php artisan schedule:run command every minute, so you need to add the following Cron entry to your server.

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

This Cron will call the Laravel command scheduler every minute. Then, Laravel evaluates your scheduled tasks and runs the tasks that are due.

When using the scheduler, you only need to add the following Cron entry to your server.

Arun P
  • 541
  • 4
  • 11