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

reviewdevs's avatar

How do I schedule some code to run at a specific time?

Hello 👋, I was wondering how can I make some code run when some time comes?

Is there is some kind of a scheduler I can use so that when, let's say, 7 PM comes tomorrow, mark all students who didn't scan the QR code as didnt_attend in the DB?

Also if there are any resources one can read about, that would be awesome

0 likes
5 replies
reviewdevs's avatar

@marianomoreyra @michaloravec Thanks a lot 😃

actually after some reading, I don't want to schedule a console command, what I want is to dynamically schedule an action for each Session

in my app, I have a session booker where I want after the session's time is up, I want to mark all users who booked the session and didn't come to be marked as didnt_attend

so I was wondering how is that possible

MarianoMoreyra's avatar
Level 25

@reviewdevs you can still schedule a console command that runs every minute (or every 10 minutes...whatever) and that command can check the database for sessions that are not marked as attended and whose session end time has finished and the mark it as didnt_attend

Or maybe you could create a Job and queue it just after the Session gets created, scheduling it to be run when the session ends:

https://laravel.com/docs/8.x/queues

https://laravel.com/docs/8.x/queues#delayed-dispatching

although I don't think that's a good approach....as you'll have a lot of Jobs updating the database instead of just one massive update...

Also, I don't know if you can delay the dispatch of a Job by that much, specially after reading this warning:

The Amazon SQS queue service has a maximum delay time of 15 minutes.

1 like
reviewdevs's avatar

Thanks @marianomoreyra, I reached a conclusion that I'll schedule a cron job every day on 6 PM till 10 PM to do the logic, I was thinking of using a delayed dispatch but yea I had the same impression that Amazon's SQS had a maximum delay of 15 minutes

Please or to participate in this conversation.