例外ポリシー

例外ポリシーは、条件がトリガーされたときに実行するアクションを定義する一連のルールです。 これらのポリシーは、ジョブ ルーター内に保存し、1つ以上のキューにアタッチできます。

トリガー

次のトリガーを使用して、アクションを実行できます:

キューの長さ- キューにジョブを追加しているときに、キューの長さが指定されたしきい値を超えたときに発生します。

待機時間- 指定されたしきい値をジョブがキューで待機しているときに発生します。

これらのトリガーが起動されると、1つまたは複数のアクションが実行され、 Event Gridを使用して例外が発生したイベントが送信されます。

アクション

キャンセル- ジョブを取り消し、キューから削除します。

再分類-変更したラベルで、指定した分類ポリシーをジョブに再適用します。

手動再分類- キュー、優先度、およびワーカー セレクターをジョブに変更します。

次の例では、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"));

次の例では、ルールを使用して例外ポリシーを構成します:

  • キューで 1 分間待機した後、ジョブの優先順位を 10 に設定します。
  • 5分間待機した後、ジョブを queue2 に移動します。
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"));