0

The scheduler is running at strange times, I have config a task to run every minute and locally runs OK, but in prod server runs like repeated at some times.

This is my Kernel.php code

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{

    protected $commands = [];


    protected function schedule(Schedule $schedule)
    {

        $schedule->call(function () {
            return true;
        })->everyMinute()->emailOutputTo('...')->thenPing('...');

    }

    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }


}

The execution output I get from the prod server:

19.06
19.07
19.08
19.09
19.10
19.11
19.12
19.13
19.16
19.16
19.16
19.17
19.18
19.21
19.21
19.21
19.22
19.23
19.25
19.25
19.26

Any ideas?

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
Daniel P.
  • 184
  • 1
  • 3
  • 16

1 Answers1

1

Looking at the output it seems it's running every minute, but sometimes it takes more time to execute the task and probably you save time after finishing the job, so for example:

19.12 -> was started at 19:12 and finished at 19:12
19.13 -> was started at 19:13 and finished at 19:13
19.16 -> was started at 19:14 and finished at 19:16
19.16 -> was started at 19:15 and finished at 19:16
19.16 -> was started at 19:16 and finished at 19:16
19.17 -> was started at 19:17 and finished at 19:17
Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
  • I understand what you say but I don't think this would be the expected behavior, because If I schedule a task eg "send SMS" at 19.16, the task is ran on a triple basis. That would mean that I send the SMS 3 times and only want one time. – Daniel P. Sep 28 '18 at 18:46
  • @DaniPereyra No, this task will run only at 19:16 (the last one), the 2 previous are from 19:14 and 19:15. You haven't included how you save those times and when you do it, but as you are running cron every minute, it's impossible that the same task is repeated 3 times. But of course details depend on your implementation. If you don't mark that you stared sending SMS/email/whatever and then next cron will run, that's true that next cron might start sending the same thing. – Marcin Nabiałek Sep 28 '18 at 18:56
  • However you can create command then and use `withoutOverlapping` if you want only single process running before previous one hasn't finished - see https://laravel.com/docs/5.7/scheduling#preventing-task-overlaps – Marcin Nabiałek Sep 28 '18 at 18:56
  • If this is laravel scheduler taking too much time to execute the same task, why this is happening on production server and not local? How can I solve or measure this? – Daniel P. Sep 28 '18 at 18:56
  • I don't know, Maybe you use different setup, maybe this is connected to DNS or something else, really hard to say. You can save start and finish time of each task to compare. So just save time when it was started and when it was finished and you will know how long each task is running. – Marcin Nabiałek Sep 28 '18 at 18:57
  • have tested when task start and ends and has a one second difference but the real issue is that the task started at 15:45:31 instead of 15:45:00. For some reason the whole scheduler is taking too much time to load, not when executing tasks. – Daniel P. Sep 28 '18 at 20:04
  • This is normal I believe. Cron works every minute but it doesn't give you guarantee that it starts when seconds are 00 – Marcin Nabiałek Sep 28 '18 at 20:05