3
3
3ton2019-01-31 17:37:05
Software design
3ton, 2019-01-31 17:37:05

How to implement a telephone queue microservice from an architectural point of view?

It is necessary to create a microservice of a telephone queue (for example, to a psychologist).
Yes
- all calls in the queue are scheduled as outgoing
calls - there can be two types of calls in the queue 1) at the scheduled time; 2) in the form of a live queue
- there should be a pause between calls, for example 5 minutes
- the maximum consultation is 30 minutes, after which the call is interrupted.
For a better understanding, I will give an example:
Consultant1 and consultant2, as well as a dozen clients.
Consultant1 has scheduled consultations with client1 (10:00), client2 (11:00), client3 (13:30), client4 (14:30), client5 (15:30)
Consultant1 has scheduled consultations with client6 (9:00) , client7 (10:00), client8 (11:00), client9 (14:00), client10 (15:00)
In addition, there are some customers who want to contact without an appointment, as a live queue.
To optimize the consultation time, we take as a basis that the consultant needs a 5-minute break between full-fledged client consultations.
Therefore, for example, it will be possible to receive 2 calls from a consultant1 before the first entry, but perhaps their questions are trifling or it will immediately turn out that the question is about another specialist, and then the queue should immediately be updated and the microservice should skip the next client from the live queue for consultation, provided that there must be at least 20 minutes before the next scheduled consultation.
2 implementation options come to mind
I option - scripting (for example PHP)
All applications are contained in the database table and with each request for a consultation, a run is made according to the existing schedule, and if this
is a scheduled consultation and the time between other scheduled consultations allows it to be accommodated, then we enter it at the requested time
- in a first come first served basis, then we fix it as a live one queue without a scheduled start time
Next, we create either a script that will be once a minute (by cron), or in a cycle with pauses of 10-30 seconds, run through the queue table and form a telephony command to create a telephone connection. If the connection fails, a pause is made for 30 seconds and an attempt is made again, after which the order is marked as broken, and we proceed to the next one.
II - a daemon is made that runs under linux
All data is also or in a different form contained in the database, or in something more operational like redis.
The daemon is written in Go, Ruby, NodeJS or others (depending on the ability of the language to communicate with Asteris / Freeswitch without dancing with a tambourine). Each consultation in the daemon as a separate object in the pool of consultations, if the consultation has expired or collapsed, the method of its completion is called, which in turn should schedule the consultant's reservation and start a request for telephony after 5 minutes. Therefore, in the pool of each consultant there can be a queue of several consultations and only one can be active at any given time. and the next one is launched not as in the first version by running the script over the table, but by the scheduled start time of the consultation object itself.
There are the following rules for the live queue
- if after the end of the consultation there is a live queue and before the next scheduled interval is more than 20 minutes, then we start it, otherwise we will start it after the end of the next scheduled one, again checking the free time before the next scheduled one.
- if a consultation is running from the live queue and the scheduled time approaches, then both interlocutors will receive a notification signal a few minutes before the consultation is interrupted and 5 minutes before the start of the scheduled consultation, the current one from the live queue will be
interrupted more optimal solutions for this task are possible in terms of reliability and stability of non-stop operation and microservice updates.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question