Capacité worker du routeur de travaux
Lors de la configuration des workers, nous voulons fournir un moyen de spécifier le nombre de travaux qu’un worker peut gérer à la fois à partir de différents canaux. Cette configuration peut être effectuée en spécifiant la capacité totale du worker et en affectant un coût par travail pour chaque canal.
Exemple : Worker qui peut gérer un travail vocal ou jusqu’à cinq travaux de conversation
Dans cet exemple, nous configurons un worker avec une capacité totale de 100 et définissons le canal vocal pour consommer 100 capacités par travail et le canal de conversation pour consommer 20 capacités par travail. Cette configuration signifie que le worker peut gérer une tâche vocale à la fois ou jusqu’à cinq travaux de conversation en même temps. Si le worker gère un ou plusieurs travaux de conversation, le worker ne peut pas effectuer de travaux vocaux tant que ces travaux de conversation ne sont pas terminés. Si le travailleur gère un travail vocal, le travailleur ne peut pas effectuer de travaux de conversation tant que la tâche vocale n’est pas terminée.
var worker = await client.CreateWorkerAsync(
new CreateWorkerOptions(workerId: "worker1", capacity: 100)
{
Queues = { "queue1" },
Channels =
{
new RouterChannel(channelId: "voice", capacityCostPerJob: 100),
new RouterChannel(channelId: "chat", capacityCostPerJob: 20)
}
});
await client.path("/routing/workers/{workerId}", "worker1").patch({
body: {
capacity: 100,
queues: ["queue1"],
channels: [
{ channelId: "voice", capacityCostPerJob: 100 },
{ channelId: "chat", capacityCostPerJob: 20 },
]
},
contentType: "application/merge-patch+json"
});
client.upsert_worker(worker_id = "worker1",
capacity = 100,
queues = ["queue1"],
channels = [
RouterChannel(channel_id = "voice", capacity_cost_per_job = 100),
RouterChannel(channel_id = "chat", capacity_cost_per_job = 20)
]
)
client.createWorker(new CreateWorkerOptions("worker1", 100)
.setQueues(List.of("queue1"))
.setChannels(List.of(
new RouterChannel("voice", 100),
new RouterChannel("chat", 20))));
Exemple : Worker qui peut gérer un travail vocal et jusqu’à deux travaux de conversation et deux travaux de messagerie en même temps
Dans cet exemple, un worker est configuré avec une capacité totale de 100. Ensuite, le canal vocal est défini pour consommer 60 capacités par travail et les canaux de conversation et de messagerie pour consommer 10 capacité par travail chacun avec un maxNumberOfJobs
ensemble de deux. Cette configuration signifie que le worker peut gérer une tâche vocale à la fois et jusqu’à deux travaux de conversation et jusqu’à deux travaux de messagerie en même temps. Étant donné que les canaux de conversation et de messagerie sont configurés avec deux maxNumberOfJobs
, ces canaux consomment jusqu’à une capacité maximale de 40 au total. Par conséquent, le worker peut toujours gérer jusqu’à un travail vocal. Le canal vocal prend « priorité » sur les autres canaux.
var worker = await client.CreateWorkerAsync(
new CreateWorkerOptions(workerId: "worker1", capacity: 100)
{
Queues = { "queue1" },
Channels =
{
new RouterChannel(channelId: "voice", capacityCostPerJob: 60),
new RouterChannel(channelId: "chat", capacityCostPerJob: 10) { MaxNumberOfJobs = 2},
new RouterChannel(channelId: "email", capacityCostPerJob: 10) { MaxNumberOfJobs = 2}
}
});
await client.path("/routing/workers/{workerId}", "worker1").patch({
body: {
capacity: 100,
queues: ["queue1"],
channels: [
{ channelId: "voice", capacityCostPerJob: 60 },
{ channelId: "chat", capacityCostPerJob: 10, maxNumberOfJobs: 2 },
{ channelId: "email", capacityCostPerJob: 10, maxNumberOfJobs: 2 }
]
},
contentType: "application/merge-patch+json"
});
client.upsert_worker(worker_id = "worker1",
capacity = 100,
queues = ["queue1"],
channels = [
RouterChannel(channel_id = "voice", capacity_cost_per_job = 60),
RouterChannel(channel_id = "chat", capacity_cost_per_job = 10, max_number_of_jobs = 2),
RouterChannel(channel_id = "email", capacity_cost_per_job = 10, max_number_of_jobs = 2)
]
)
client.createWorker(new CreateWorkerOptions("worker1", 100)
.setQueues(List.of("queue1"))
.setChannels(List.of(
new RouterChannel("voice", 60),
new RouterChannel("chat", 10).setMaxNumberOfJobs(2),
new RouterChannel("email", 10).setMaxNumberOfJobs(2))));