Classification d’un travail
Découvrez comment utiliser une stratégie de classification dans le routeur de travaux pour résoudre dynamiquement la file d’attente et la priorité tout en liant également des sélecteurs de Worker à un travail.
Prérequis
- Compte Azure avec un abonnement actif. Créez un compte gratuitement.
- Une ressource Communication Services déployée. Créez une ressource Communication Services.
- Facultatif : suivez le Guide de démarrage rapide pour commencer à utiliser le routeur de travaux
Créer une stratégie de classification
L’exemple suivant tire parti des expressions PowerFx pour sélectionner la file d’attente et la priorité. L’expression tente de faire correspondre l’étiquette de travail appelée Region
égale à NA
la mise en place du travail dans le XBOX_NA_QUEUE
fichier . Sinon, le travail est envoyé à la file d’attente XBOX_DEFAULT_QUEUE
de secours telle que définie par fallbackQueueId
. En outre, la priorité est 10
si une étiquette appelée Hardware_VIP
a été mise en correspondance, sinon elle est 1
.
var classificationPolicy = await administrationClient.CreateClassificationPolicyAsync(
new CreateClassificationPolicyOptions(classificationPolicyId: "XBOX_NA_QUEUE_Priority_1_10")
{
Name = "Select XBOX Queue and set priority to 1 or 10",
QueueSelectorAttachments =
{
new ConditionalQueueSelectorAttachment(condition: new ExpressionRouterRule("job.Region = \"NA\""),
queueSelectors: new List<RouterQueueSelector>
{
new(key: "Id", labelOperator: LabelOperator.Equal, value: new RouterValue("XBOX_NA_QUEUE"))
})
},
FallbackQueueId = "XBOX_DEFAULT_QUEUE",
PrioritizationRule = new ExpressionRouterRule("If(job.Hardware_VIP = true, 10, 1)"),
});
var classificationPolicy = await client.path("/routing/classificationPolicies/{classificationPolicyId}",
"XBOX_NA_QUEUE_Priority_1_10").patch({
body: {
name: "Select XBOX Queue and set priority to 1 or 10",
queueSelectorAttachments: [{
kind: "conditional",
condition: {
kind: "expression",
expression: 'job.Region = "NA"'
},
queueSelectors: [{
key: "Id",
labelOperator: "equal",
value: "XBOX_NA_QUEUE"
}]
}],
fallbackQueueId: "XBOX_DEFAULT_QUEUE",
prioritizationRule: {
kind: "expression",
expression: "If(job.Hardware_VIP = true, 10, 1)"
}
},
contentType: "application/merge-patch+json"
});
classification_policy: ClassificationPolicy = administration_client.upsert_classification_policy(
classification_policy_id = "XBOX_NA_QUEUE_Priority_1_10",
name = "Select XBOX Queue and set priority to 1 or 10",
queue_selector_attachments = [
ConditionalQueueSelectorAttachment(
condition = ExpressionRouterRule(expression = 'job.Region = "NA"'),
queue_selectors = [
RouterQueueSelector(key = "Id", label_operator = LabelOperator.EQUAL, value = "XBOX_NA_QUEUE")
]
)
],
fallback_queue_id = "XBOX_DEFAULT_QUEUE",
prioritization_rule = ExpressionRouterRule(expression = "If(job.Hardware_VIP = true, 10, 1)")))
ClassificationPolicy classificationPolicy = administrationClient.createClassificationPolicy(
new CreateClassificationPolicyOptions("XBOX_NA_QUEUE_Priority_1_10")
.setName("Select XBOX Queue and set priority to 1 or 10")
.setQueueSelectors(List.of(new ConditionalQueueSelectorAttachment(
new ExpressionRouterRule("job.Region = \"NA\""),
List.of(new RouterQueueSelector("Id", LabelOperator.EQUAL, new RouterValue("XBOX_NA_QUEUE"))))))
.setFallbackQueueId("XBOX_DEFAULT_QUEUE")
.setPrioritizationRule(new ExpressionRouterRule().setExpression("If(job.Hardware_VIP = true, 10, 1)")));
Envoi du travail
L’exemple suivant entraîne l’évaluation de la stratégie de classification des étiquettes de travail. Le résultat place le travail dans la file d’attente appelée XBOX_NA_QUEUE
et définit la priorité 1
sur . Avant l’évaluation de la stratégie de classification, l’état du travail est pendingClassification
. Une fois la stratégie de classification évaluée, l’état du travail est mis à jour vers queued
.
var job = await client.CreateJobWithClassificationPolicyAsync(new CreateJobWithClassificationPolicyOptions(
jobId: "job1",
channelId: "voice",
classificationPolicyId: classificationPolicy.Value.Id)
{
Labels =
{
["Region"] = new RouterValue("NA"),
["Caller_Id"] = new RouterValue("7805551212"),
["Caller_NPA_NXX"] = new RouterValue("780555"),
["XBOX_Hardware"] = new RouterValue(7)
}
});
var job = await client.path("/routing/jobs/{jobId}", "job1").patch({
body: {
channelId: "voice",
classificationPolicyId: "XBOX_NA_QUEUE_Priority_1_10",
labels: {
Region: "NA",
Caller_Id: "7805551212",
Caller_NPA_NXX: "780555",
XBOX_Hardware: 7
}
},
contentType: "application/merge-patch+json"
});
job = client.upsert_job(
job_id = "job1",
channel_id = "voice",
classification_policy_id = "XBOX_NA_QUEUE_Priority_1_10",
labels = {
"Region": "NA",
"Caller_Id": "7805551212",
"Caller_NPA_NXX": "780555",
"XBOX_Hardware": 7
}
)
RouterJob job = client.createJob(new CreateJobWithClassificationPolicyOptions("job1", "voice", "XBOX_NA_QUEUE_Priority_1_10")
.setLabels(Map.of(
"Region", new RouterValue("NA"),
"Caller_Id": new RouterValue("7805551212"),
"Caller_NPA_NXX": new RouterValue("780555"),
"XBOX_Hardware": new RouterValue(7)
)));
Attachement de sélecteurs de collaborateurs
Vous pouvez utiliser la stratégie de classification pour attacher davantage de sélecteurs de travail à un travail.
Attachements statiques
Dans cet exemple, la stratégie de classification est configurée avec une pièce jointe statique, qui attache toujours le sélecteur d’étiquette spécifié à un travail.
await administrationClient.CreateClassificationPolicyAsync(
new CreateClassificationPolicyOptions("policy-1")
{
WorkerSelectorAttachments =
{
new StaticWorkerSelectorAttachment(new RouterWorkerSelector(
key: "Foo", labelOperator: LabelOperator.Equal, value: new RouterValue("Bar")))
}
});
await client.path("/routing/classificationPolicies/{classificationPolicyId}", "policy-1").patch({
body: {
workerSelectorAttachments: [{
kind: "static",
workerSelector: { key: "Foo", labelOperator: "equal", value: "Bar" }
}]
},
contentType: "application/merge-patch+json"
});
administration_client.upsert_classification_policy(
classification_policy_id = "policy-1",
worker_selector_attachments = [
StaticWorkerSelectorAttachment(
worker_selector = RouterWorkerSelector(key = "Foo", label_operator = LabelOperator.EQUAL, value = "Bar")
)
])
administrationClient.createClassificationPolicy(new CreateClassificationPolicyOptions("policy-1")
.setWorkerSelectorAttachments(List.of(
new StaticWorkerSelectorAttachment(new RouterWorkerSelector("Foo", LabelOperator.EQUAL, new RouterValue("Bar"))))));
Attachements conditionnels
Dans cet exemple, la stratégie de classification est configurée avec un attachement conditionnel. Il évalue donc une condition par rapport aux étiquettes de travail pour déterminer si les sélecteurs d’étiquettes indiqués doivent être attachés au travail.
await administrationClient.CreateClassificationPolicyAsync(
new CreateClassificationPolicyOptions("policy-1")
{
WorkerSelectorAttachments =
{
new ConditionalRouterWorkerSelectorAttachment(
condition: new ExpressionRouterRule("job.Urgent = true"),
workerSelectors: new List<RouterWorkerSelector>
{
new(key: "Foo", labelOperator: LabelOperator.Equal, value: new RouterValue("Bar"))
})
}
});
await client.path("/routing/classificationPolicies/{classificationPolicyId}", "policy-1").patch({
body: {
workerSelectorAttachments: [{
kind: "conditional",
condition: { kind: "expression", expression: "job.Urgent = true" },
workerSelectors: [{ key: "Foo", labelOperator: "equal", value: "Bar" }]
}]
},
contentType: "application/merge-patch+json"
});
administration_client.upsert_classification_policy(
classification_policy_id = "policy-1",
worker_selector_attachments = [
ConditionalWorkerSelectorAttachment(
condition = ExpressionRouterRule(expression = "job.Urgent = true"),
worker_selectors = [
RouterWorkerSelector(key = "Foo", label_operator = LabelOperator.EQUAL, value = "Bar")
]
)
])
administrationClient.createClassificationPolicy(new CreateClassificationPolicyOptions("policy-1")
.setWorkerSelectorAttachments(List.of(new ConditionalRouterWorkerSelectorAttachment(
new ExpressionRouterRule("job.Urgent = true"),
List.of(new RouterWorkerSelector("Foo", LabelOperator.EQUAL, new RouterValue("Bar")))))));
Attachements pass-through
Dans cet exemple, la stratégie de classification est configurée pour attacher un sélecteur de collaborateur ("Foo" = "<value comes from "Foo" label of the job>"
) au travail.
await administrationClient.CreateClassificationPolicyAsync(
new CreateClassificationPolicyOptions("policy-1")
{
WorkerSelectorAttachments =
{
new PassThroughWorkerSelectorAttachment(key: "Foo", labelOperator: LabelOperator.Equal)
}
});
await client.path("/routing/classificationPolicies/{classificationPolicyId}", "policy-1").patch({
body: {
workerSelectorAttachments: [{ kind: "passThrough", key: "Foo", labelOperator: "equal" }]
},
contentType: "application/merge-patch+json"
});
administration_client.upsert_classification_policy(
classification_policy_id = "policy-1",
worker_selector_attachments = [
PassThroughWorkerSelectorAttachment(
key = "Foo", label_operator = LabelOperator.EQUAL, value = "Bar")
])
administrationClient.createClassificationPolicy(new CreateClassificationPolicyOptions("policy-1")
.setWorkerSelectorAttachments(List.of(new PassThroughWorkerSelectorAttachment("Foo", LabelOperator.EQUAL))));
Attachements par allocation pondérée
Dans cet exemple, la stratégie de classification est configurée avec un attachement par allocation pondérée. Cette stratégie divise les travaux en fonction des pondérations spécifiées et attachent différents sélecteurs en conséquence. Ici, 30 % des travaux doivent revenir aux collaborateurs dont l’étiquette Vendor
a la valeur A
et 70 % aux collaborateurs dont l’étiquette Vendor
a la valeur B
.
await administrationClient.CreateClassificationPolicyAsync(new CreateClassificationPolicyOptions("policy-1")
{
WorkerSelectorAttachments =
{
new WeightedAllocationWorkerSelectorAttachment(new List<WorkerWeightedAllocation>
{
new (weight: 0.3, workerSelectors: new List<RouterWorkerSelector>
{
new (key: "Vendor", labelOperator: LabelOperator.Equal, value: new RouterValue("A"))
}),
new (weight: 0.7, workerSelectors: new List<RouterWorkerSelector>
{
new (key: "Vendor", labelOperator: LabelOperator.Equal, value: new RouterValue("B"))
})
})
}
});
await client.path("/routing/classificationPolicies/{classificationPolicyId}", "policy-1").patch({
body: {
workerSelectorAttachments: [{
kind: "weightedAllocation",
allocations: [
{
weight: 0.3,
workerSelectors: [{ key: "Vendor", labelOperator: "equal", value: "A" }]
},
{
weight: 0.7,
workerSelectors: [{ key: "Vendor", labelOperator: "equal", value: "B" }]
}]
}]
},
contentType: "application/merge-patch+json"
});
administration_client.upsert_classification_policy(
classification_policy_id = "policy-1",
worker_selector_attachments = [
WeightedAllocationWorkerSelectorAttachment(allocations = [
WorkerWeightedAllocation(weight = 0.3, worker_selectors = [
RouterWorkerSelector(key = "Vendor", label_operator = LabelOperator.EQUAL, value = "A")
]),
WorkerWeightedAllocation(weight = 0.7, worker_selectors = [
RouterWorkerSelector(key = "Vendor", label_operator = LabelOperator.EQUAL, value = "B")
])
])
])
administrationClient.createClassificationPolicy(new CreateClassificationPolicyOptions("policy-1")
.setWorkerSelectorAttachments(List.of(new WeightedAllocationWorkerSelectorAttachment(
List.of(new WorkerWeightedAllocation(0.3, List.of(
new RouterWorkerSelector("Vendor", LabelOperator.EQUAL, new RouterValue("A")),
new RouterWorkerSelector("Vendor", LabelOperator.EQUAL, new RouterValue("B"))
)))))));
Reclassifier un travail après envoi
Une fois que le routeur de travaux a reçu et classifié un travail à l’aide d’une stratégie, vous avez la possibilité de le reclassifier à l’aide du kit SDK. L’exemple suivant illustre une façon d’augmenter la priorité du travail en 10
spécifiant simplement l’ID de travail, en appelant la UpdateJobAsync
méthode et en mettant à jour classificationPolicyId et en incluant l’étiquetteHardware_VIP
.
await client.UpdateJobAsync(new RouterJob("job1") {
ClassificationPolicyId = classificationPolicy.Value.Id,
Labels = { ["Hardware_VIP"] = new RouterValue(true) }});
var job = await client.path("/routing/jobs/{jobId}", "job1").patch({
body: {
classificationPolicyId: classificationPolicy.body.id,
labels: { Hardware_VIP: true }
},
contentType: "application/merge-patch+json"
});
client.upsert_job(
job_id = "job1",
classification_policy_id = classification_policy.id,
labels = { "Hardware_VIP": True }
)
client.updateJob(new RouterJob("job1")
.setClassificationPolicyId(classificationPolicy.getId())
.setLabels(Map.of("Hardware_VIP", new RouterValue(true))));
Remarque
Si les étiquettes de travaux, queueId, channelId ou sélecteurs de travail sont mis à jour, toutes les offres existantes sur le travail sont révoquées et vous recevez un événement RouterWorkerOfferRevoked pour chaque offre d’EventGrid. Le travail est re-mis en file d’attente et vous recevez un événement RouterJobQueued . Les offres de travail peuvent également être révoquées lorsque la capacité totale d’un worker est réduite ou que les canaux sont mis à jour.