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
6 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.

Glukinho's avatar

I don't know what exactly should happen on "auction close". But you can use another approach.

Let's say you have Auction model and you want an auction to close after 5 minutes of the last bid.

  1. have closed_at timestamp field on auctions table
  2. every bid updates auction's closed_at to 300 seconds in future

Then you have any auction closed in 5 minutes exactly after last bid, without queue at all. You can queue some related things like notifications if you need. Or, have a scheduled command every minute which gathers just closed auctions (where closed_at is less than 1 minute past) and does whatever you need.

And I should tell I don't see how it all is related to Reverb...

ninjapeps's avatar

I'm using reverb to listen to the events and update the auction display. Up to three are active at any given time and as soon as one auction closes, it's removed from the display and the next item is put up. Client wants the auctions to close after 3 to 5 seconds of inactivity. I need real-time updates since users won't have time to refresh the page hence reverb.

The way they want this work is weird to me since it's not at all how a site like Ebay works but it's apparently something that's done in Japan and they want to make something like it over in our country.

Glukinho's avatar

How about that: every bid updates auction's closed_at to 10 seconds in future and pushes this information to clients via Reverb.

On client side you store and update closed_at for each visible auction. You hide an auction (or visually mark it closed) at desired moment if there were no updates for this auction, otherwise you postpone hiding. You may additionally request the backend for auction's current status right before hiding, just to be sure.

There can be issues with time sync between server and clients; to get them around you can send to clients "auction A closes in 10 seconds" instead of "auction A closes at 2026-06-11 12:34:56".

Please or to participate in this conversation.