ninjapeps's avatar

Creating an event to check for inactivity

I'm trying to make a sort of real time auction site with each auction ideally lasting only as long as people are bidding. If no new bids are detected within a few seconds of the last bid, then the auction will close. Originally, I did this by having an event fire off when someone bids that sleeps for a few seconds and then checks if there are any new bids when it finally runs. It worked but then I realized that the event queue would get clogged by all of these inactivity checker events.

Is there a way to remove specific events from the queue? Or some other better way to do this? Thanks.

0 likes
1 reply
Glukinho's avatar

You're right, sleeping in code is not the best approach. Instead you can dispatch a job to some time in future:

CloseAuctionJob::dispatch($auction)->dispatch()->delay(300);

So the job will be actually executed by queue worker after 5 minutes (300 seconds). But you should know this is not guaranteed and the job may be run later, it depends on number of workers and number of jobs in a queue. This may be critical to your app.

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

Please or to participate in this conversation.