I have a system in laravel that has some services to buy, customers buy randomly at any time of the day, before the service is performed there is a pre-check of the registered information. The company has employees to do this work, each customer that comes in has an employee responsible for checking their information. I need to implement a service rotation, for example: If I have 3 employees online, then I have [1,2,3], when a customer buys, employee 1 checks the information and the queue becomes [2,3,1], now the next customer to buy will be the attendant 2 getting [3, 1, 2]. .. and so on. Does anyone have any ideas on how I can implement this?? The algorithm needs to work regardless of the size of the array.
I need the array to persist across changing states to work on the next client. Currently I get it randomly with eloquent.
$users = Usuario::where('ativo', 'sim')->inRandomOrder()->get()
If you have access to a redis instance, this could be very simple.
When employees log in, add them to the queue with
Redis::rpush('queueName', $employeeId);
When a customer buys, assign employee with
$assignedEmployeee = Redis::lpop('queueName');
// also immediately readd them to the back of the queue
Redis::rpush('queueName', $assignedEmployeee);
When an employee logs out, you will have to filter the list to remove the id, or you can check it during purchase to see if that employee is still online, either way this would be a good starting point