Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

SilvaDreamdeal's avatar

Scheduler Running before hours

Hello

I'm having some trouble using forge scheduler vs laravel scheduler

In my Laravel project, I have defined some jobs like this:

protected function schedule(Schedule $schedule)
   {
      
      //$schedule->job(new \App\Domains\Works\Jobs\NotifyMissingDiary())->dailyAt("03:00");

      $schedule->job(new InvoicesExpiredJob)->everyMinute();
      
      $schedule->job(new InvoicesExpiringJob)->everyMinute();

      

      // -------------------------------------------------------

      $schedule->job(new DiariesToApprove)->dailyAt("03:00");

      $schedule->job(new DiariesToDo)->dailyAt("03:00");

      $schedule->job(new DashboardWorksData)->dailyAt("03:00");
      
      $schedule->job(new DashboardMORendimentoData)->dailyAt("03:00");

      $schedule->job(new DashboardUORendimentoData)->dailyAt("03:00");

      // -------------------------------------------------------
   }

The first two (InvoicesExpiredJob, InvoicesExpiringJob) are ok. I want them to run every minute. The other jobs I just need them to start every day at 3 AM. But thats the only time they should run. At 3AM each day

At forge, I scheduled a job to run every minute.

As I understand, each minute forge will check if there's a job to run, an runs that job The first two, as I said before, are running ok.

But why are the others also running? Shouldn't they be running just one time at 3 AM each day?

0 likes
8 replies
Snapey's avatar

yes they should run once per day, and running it on forge should make no difference

so locally, if you run php artisan schedule:run it should only run the two invoices jobs unless it happens to be exactly 3am

SilvaDreamdeal's avatar

@Snapey thanks

thats what I thought. The first two send to my email invoices expired or near expiration (just one email per invoice)

The others just run one time, each day at 3AM and send emails about diaries that the users needs to do, and other stuff. The fact is that I was confident that everything was ok. I released the forge scheduler at 5PM

At 7PM I checked my email and I was surprised with near 100 emails from the jobs that are suposed to run at 3AM only

1 like
Snapey's avatar

@SilvaDreamdeal each of these 3am jobs should only send one email?

remember that the scheduler runs in the timezone of the server. I could be that these emails were all sent at the same time, eg at 3am utc this being some time between 5pm and 7pm your time?

SilvaDreamdeal's avatar

@Snapey Server is with the correct timezone. I scheduled to run at 14.20h at 14.00h

Nothing happened in the first 20 minutes. The job started to run at 14.20 as scheduled and never stopped. I received emails minute by minute

Just forge is scheduled to run minute by minute

It seems he is ignoring the kernel.php jobs scheduler and runs the jobs with forge (minute by minute)

SilvaDreamdeal's avatar

@Snapey tried to put to run daily(). It is supposed to run just at midnight I think

protected function schedule(Schedule $schedule)
   {
      
      //$schedule->job(new \App\Domains\Works\Jobs\NotifyMissingDiary())->dailyAt("03:00");

      //$schedule->job(new InvoicesExpiredJob)->everyMinute();
      
      //$schedule->job(new InvoicesExpiringJob)->everyMinute();

      //$schedule->job(new DiariesToApprove)->daily();

      $schedule->job(new DiariesToDo)->daily();

      //$schedule->job(new DashboardWorksData)->dailyAt("03:00");
      
      //$schedule->job(new DashboardMORendimentoData)->dailyAt("03:00");

      //$schedule->job(new DashboardUORendimentoData)->dailyAt("03:00");
   }

I'm using this command at forge, when scheduling:

php /home/forge/link.com/artisan schedule:run

When I resumed the forge job, it started to send emails. He just ignores what I put in the function

SilvaDreamdeal's avatar

it seems its a problem from daily function

If I run everyMinute or EveryTwoMinute it works

If I put to run at a specific time, never runs

1 like
SilvaDreamdeal's avatar
SilvaDreamdeal
OP
Best Answer
Level 1

@snapey Can you explain me whats the difference? I'm sorry to ask, but I cant understand the difference. The time is the same

$schedule->job(new DiariesToDo)->dailyAt('15:15');

VS

$schedule->call(function () {
         new DiariesToDo();
      })->dailyAt('15:15');

The first one is sending minute by minute with forge execution...

The second is sending just at the time I asked for (15.15h) one per day as I want.

Why the first is not working?

Snapey's avatar

I didn't like to ask why you were using a job.

I your first example, you create a job on the default queue.

In the second example, you run the class immediately.

Obviously using job puts the task on the queue. You should examine if you have the same queue settings locally. You are running a queue worker locally?

How does your job terminate? Somehow it is being kept on the queue, or is spawning a copy.

Please or to participate in this conversation.