Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Attendance rotation algorithm in laravel

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()

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading