How to wait for a user action on a Job?

Asked

Viewed 51 times

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.

1 answer

-1

Good afternoon, I had a similar problem, with the exception of time, the solution I found was to count the amount of records in a query and go run with a new call through a Trigger in jquery:

$(Document). ready(Function (){

var base = $(#base1). val(); var progress = $(#progress). val();

if($progress < $base){ $(#buttonAtualize). Trigger('click'); }

}

I don’t know if this solves for you but it can be a clue, if possible return, I was curious about the way you did and I didn’t understand the doubt.

}

  • 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.