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
3 replies
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)->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

ninjapeps's avatar

Many thanks. This is helpful to know, though I feel that it could still end up with there being too many close auction jobs on the queue. Still much better than what I originally did.

I'm still very new to reverb and went from making a very small scale chat app to a potentially large auction app in the span of one project so I feel out of my depth.

ninjapeps's avatar

Sorry, I just realized that I call events using broadcast inside an event, not through jobs. Delay doesn't seem to be something I can use with broadcast.

Please or to participate in this conversation.