5
The Situation
Having a service queue, where whenever a user enters the queue he receives a position number in the queue, I need to request the presence of the first of the queue.
If the first row does not respond to the request in up to 1 minute (60 seconds) it must be removed from the queue, the queue positions are updated and the process is repeated, until the first one meets the request or the queue is empty, in such cases the process stops until a new request for the queue is made.
What do I have
The queue is saved as json in the field queue
on the table attendants
database, according to the login of the users in the format:
[57,12,15,99,157] //Fila com os IDs dos usuários
To process the queue currently I do something similar to
public function offerToFirst(Collection $queue, Attendance $attendance)
{
if ($queue->isNotEmpty()) {
$queue->first();
if ($attendance->current_user_id === $queue->first()) {
return null;
}
sleep(60);
$this->offerToFirst($queue, $attendance);
}
return null;
}
The Problem
As it is being done today the request takes at least 60 seconds ad infinitum and I would like the processing to stop as soon as one of the actions happens first:
- Exceed 60 seconds
- The user who received the offer of service accept
- The user who received the offer of service refuse
I’m thinking of doing a job that will process the queue without having to block the requisition for it. This job would listen to an event triggered by requests made by the user to accept or refuse the offer, but I do not know how to treat Job to hear a specific event.
In the end I refactored all the processing in a way that each offer was just trimming one person and added in the process several verification steps to be able to kill the process during execution
– Erlon Charles