Twilio TaskRouter - Controlling the order which TaskQueue selects Workers - twilio

Ahoy! First time TaskRouter user here. I have about 500 Workers which meet the TargetWorkers expression for my TaskQueue. I also have a priority for each Worker, where this priority is any integer.
Ideally: I'd like Tasks to be assigned to my Workers based on the Worker's priority. Doesn't need to be exactly like this, but that's my ideal. Any ideas on how to build this out in Twilio TaskRouter?
Example: Given two available Workers A and B, where A has high priority (1025) and B has lower priority (2). I want the incoming task to be assigned to A whenever possible. The task should only go to Worker B if Worker A is not available, times out, or rejects the offer.
Is there documentation somewhere which explains the order in which TaskQueues select between available workers?

Related

Twilio TaskRouter - how to include certain Unavailable workers to pick up tasks?

In our Twilio application we would like to use TaskRouter to distribute incoming calls. Suppose we would like to handle the following scenario:
All Workers login to front-end application and have their status set to Available. If there are any incoming calls, Workers receive them in the UI.
Some Workers have this custom attribute: {"work_hours": [600, 1600], "phone_numbers": ["+1...", "+1..."]}. If for some reason this Worker becomes Unavailable during their working hours set between "work_hours" attribute, we would still like to have incoming calls forwarded to their personal phones from "phone_numbers" attribute.
If the above fails, we would like to forward the incoming call to Voicemail.
Basically, my question is whether it is possible to include Unavailable workers to Workflows and Task Queues? The above scenario would most likely require 3 Task Queues: one for all Available Workers, one for Unavailable but with "work_hours" attributes where taskrouter.currentTime is between those hours and one for Voicemail.
Twilio Solutions Architect here!
I think that you may already found a solution for your problem, but in case someone else is having this problem, here's my solution:
The best way to do this is actually creating a new Activity on TaskRouter of type Unavailable with Work Hours that is is an available Activity. With that state created, you can set the worker availability to this state when they are on this use case, and with the Task Router Workflows, you can have specific queues for these agents and using the routing strategies, bring a task to this queue if necessary.
Regarding to call the agents on their personal phone numbers, you can create a conference between the original call and the agent's phone number and have them connected.
This is a bit tricky, but is completely possible.

How to ring multiple workers in Twilio Flex

In Twilio Flex, when a call comes in, I want all workers in a given queue to ring.
They should all be able to pick up the call and the first one to do so is connected to the customer while the call disappear for the others.
For now, TaskRouter seems to select a single eligible worker to send the call.
How can I have TaskRouter to simulring all eligible workers instead of ringing them one by one?
Alan's comment got me in the right direction.
To have multiple workers ring at the same time, just increase the MAX RESERVED WORKERS property in the TaskQueue.

Prevent worker from receiving voice tasks by updating their voice channel capacity

I'm currently using task router to route calls to my workers and I want to temporarily prevent certain workers from getting assigned voice tasks. I thought by updating the worker channel capacity for voice to 0 or marking the voice worker channel as unavailable would mean that while the worker remains a part of the queues (based on their custom attributes), if there are any voice tasks coming in, they would not be assigned to that worker. That does not seem to be the case, my worker still receives reservations for voice tasks.
I tried to update my queue to only include workers that have voice capacity by adding this check to the Queue expression '... AND worker.channel.voice.configured_capacity > 0', however when saving the queue in the Console, I get an error saying 'Worker channel capacity expressions not allowed in TargetWorkersExpression on TaskQueue' which leads me to believe that this is not the right thing to do.
The only other solution I can see is to add the worker channel capacity check mentioned above to the target expression at every step of my workflow but that would be harder to maintain.
I can't help but feel that there's something I've missed or misunderstood about how the worker channel capacity works or what it is used for. For what is worth, multitasking is disabled for my workspace.
Twilio developer evangelist here.
Adjusting the capacity when you are not using multitasking won't make a difference.
I would recommend using a custom attribute on the worker and then filtering based on that within the target workers expression instead.

How can I use Sidekiq delay with a worker

I have a situation where I have a worker that makes multiple calls to an external API. The problem is that we have a threshold of many calls we can make to this API per hour.
What I'd like to do is to create a worker which will make these many sequential calls to this external API. If in between these calls we get an error because we've reached the number of connections we're allowed in that hour, the worker would then save the document and schedule a new worker to complete the remaining API calls at a later time (maybe 1, 2 hours later. Ideally this should be configurable e.g.: 10mins, 1hour, etc).
Is there someway I could achieve this?
With SideKiq you can scheduled when a job will be executed with a friendly API :
MyWorker.perform_in(3.hours, 'mike', 1) # Expect a duration
MyWorker.perform_at(3.hours.from_now, 'mike', 1) # Expect a date
Check it out : Scheduled Jobs
You want Sidekiq Enterprise and its Rate Limiting API. The alternative is tracking the rate limit yourself and rescheduling the job manually.
https://github.com/mperham/sidekiq/wiki/Ent-Rate-Limiting

Prioritizing jobs on Sidekiq

Imagine a simple dating app, which provides you a potential match every day. When users first sign up, the following happens -
They are sent an email - "Welcoming to the Dating app!"
A custom matching job kicks off to find them a match for the day and sends them an email - "You have a match!"
If I choose to mass-enroll several thousand people, the job queue will be populated with several thousand jobs of both #1 and #2. It's important that they receive the email first before getting a match, since otherwise it makes for a confusing experience.
I have -
# config/sidekiq.rb
:queues:
- high_priority
- default
- low_priority
As per this page, those queues should process in the listed order.
How does this prioritization work? Is the entire high priority queue drained before picking an item of the default or low_priority queues? Or is it just checked more often, still allowing some lower priority jobs to be processed at the same time?
As a follow-up to #1, is there a way to ensure that for a specific user, they receive the welcome email before they receive their match email? The former will be in the high_priority queue and the latter in the default priority, but there's no guarantee either queue is in any particular order for users.
Thanks!
Each time Sidekiq looks for a job in Redis, it will check high_priority first, then default, then low_priority. The jobs in default will just sit there as long as there are jobs in high_priority.

Resources