Laravel Task Scheduling - when does the execution starts

496 Views Asked by At

Laravel Task Scheduling has options like, everyMinute() which will run a command every minute. I want to know what is the time it actually starts executing. Is it when I run the server or any specific second of the minute?
I am trying to run a function depending on the time difference. Here's a pseudocode

Run myCustomFunction() if diffInMin(now, customTime) <= 1

I thought it will run 1 time but it ran twice every time.

1

There are 1 best solutions below

2
On

The scheduler usually runs every minute right around the zero secound mark based on the server's current time as @apokryfos mentioned.

Assuming the customTime is a fixed DateTime, what makes you think the code you wrote will only run once?

  • When now() === customTime the diffInMin() would be zero so the condition diffInMin(now, customTime) <= 1 will evaluate to true.
  • The next minute, the diffInMin() would be 1, so the condition diffInMin(now, customTime) <= 1 will still evaluate to true.