Bagikan melalui


Kebijakan Pengecualian

Kebijakan Pengecualian adalah sekumpulan aturan yang menentukan tindakan apa yang akan dijalankan saat kondisi dipicu. Anda dapat menyimpan kebijakan ini di dalam Job Router lalu melampirkannya ke satu atau beberapa Antrean.

Memicu

Pemicu berikut dapat digunakan untuk mendorong tindakan:

Panjang Antrean - Diaktifkan saat panjang antrean melebihi ambang yang ditentukan saat menambahkan pekerjaan ke antrean.

Waktu Tunggu - Aktif saat pekerjaan telah menunggu dalam antrean untuk ambang yang ditentukan.

Saat pemicu ini diaktifkan, mereka akan menjalankan satu atau beberapa tindakan dan mengirim Peristiwa Yang Dipicu Pengecualian melalui Event Grid.

Tindakan

Batal - Membatalkan pekerjaan dan menghapusnya dari antrean.

Reclassify - Menerapkan kembali Kebijakan Klasifikasi yang ditentukan dengan label yang dimodifikasi ke pekerjaan.

Manual Reclassify - Memodifikasi pemilih antrean, prioritas, dan pekerja ke pekerjaan.

Contoh

Dalam contoh berikut, kami mengonfigurasi kebijakan pengecualian yang akan membatalkan pekerjaan sebelum bergabung dengan antrean dengan panjang lebih besar dari 100.

await administrationClient.CreateExceptionPolicyAsync(new CreateExceptionPolicyOptions(
    exceptionPolicyId: "maxQueueLength",
    exceptionRules: new List<ExceptionRule>
    {
        new (id: "cancelJob",
            trigger: new QueueLengthExceptionTrigger(threshold: 100),
            actions: new List<ExceptionAction>{ new CancelExceptionAction() })
    }) { Name = "Max Queue Length Policy" });
await administrationClient.path("/routing/exceptionPolicies/{exceptionPolicyId}", "maxQueueLength").patch({
    body: {
        name: "Max Queue Length Policy",
        exceptionRules: [
        {
            id: "cancelJob",
            trigger: { kind: "queueLength", threshold: 100 },
            actions: [{ kind: "cancel" }]
        }
      ]
    }
});
administration_client.upsert_exception_policy(
    exception_policy_id = "maxQueueLength",
    name = "Max Queue Length Policy",
    exception_rules = [
        ExceptionRule(
            id = "cancelJob",
            trigger = QueueLengthExceptionTrigger(threshold = 100),
            actions = [ CancelExceptionAction() ]
        )
    ]
)
administrationClient.createExceptionPolicy(new CreateExceptionPolicyOptions("maxQueueLength",
    List.of(new ExceptionRule(
        "cancelJob",
        new QueueLengthExceptionTrigger(100),
        List.of(new CancelExceptionAction())))
).setName("Max Queue Length Policy"));

Dalam contoh berikut, kami mengonfigurasi Kebijakan Pengecualian dengan aturan yang akan:

  • Atur prioritas pekerjaan ke 10 setelah menunggu dalam antrean selama 1 menit.
  • Pindahkan pekerjaan ke queue2 setelah menunggu selama 5 menit.
await administrationClient.CreateExceptionPolicyAsync(new CreateExceptionPolicyOptions(
    exceptionPolicyId: "policy2",
    exceptionRules: new List<ExceptionRule>
    {
        new(
            id: "increasePriority",
            trigger: new WaitTimeExceptionTrigger(threshold: TimeSpan.FromMinutes(1)),
            actions: new List<ExceptionAction>
            {
                new ManualReclassifyExceptionAction { Priority = 10 }
            }),
        new(
            id: "changeQueue",
            trigger: new WaitTimeExceptionTrigger(threshold: TimeSpan.FromMinutes(5)),
            actions: new List<ExceptionAction>
            {
                new ManualReclassifyExceptionAction { QueueId = "queue2" }
            })
    }) { Name = "Escalation Policy" });
await administrationClient.path("/routing/exceptionPolicies/{exceptionPolicyId}", "policy2").patch({
    body: {
        name: "Escalation Policy",
        exceptionRules: [
        {
            id: "increasePriority",
            trigger: { kind: "waitTime", thresholdSeconds: "60" },
            actions: [{ "manual-reclassify", priority: 10 }]
        },
        {
            id: "changeQueue",
            trigger: { kind: "waitTime", thresholdSeconds: "300" },
            actions: [{ kind: "manual-reclassify", queueId: "queue2" }]
        }]
    },
    contentType: "application/merge-patch+json"
  });
administration_client.upsert_exception_policy(
    exception_policy_id = "policy2",
    name = "Escalation Policy",
    exception_rules = [
        ExceptionRule(
            id = "increasePriority",
            trigger = WaitTimeExceptionTrigger(threshold_seconds = 60),
            actions = [ ManualReclassifyExceptionAction(priority = 10) ]
        ),
        ExceptionRule(
            id = "changeQueue",
            trigger = WaitTimeExceptionTrigger(threshold_seconds = 60),
            actions = [ ManualReclassifyExceptionAction(queue_id = "queue2") ]
        )
    ]
)
administrationClient.createExceptionPolicy(new CreateExceptionPolicyOptions("policy2", List.of(
    new ExceptionRule("increasePriority", new WaitTimeExceptionTrigger(Duration.ofMinutes(1)),
        List.of(new ManualReclassifyExceptionAction().setPriority(10))),
    new ExceptionRule("changeQueue", new WaitTimeExceptionTrigger(Duration.ofMinutes(5)),
        List.of(new ManualReclassifyExceptionAction().setQueueId("queue2"))))
).setName("Escalation Policy"));