Uredi

Deli z drugimi prek


Manage a queue

This guide outlines the steps to create and manage a Job Router queue.

Prerequisites

Create a distribution policy and a queue

To create a simple queue in Job Router, use the SDK to specify the queue ID, name, and a distribution policy ID. The distribution policy must be created in advance as the Job Router will validate its existence upon creation of the queue. In the following example, a distribution policy is created to control how Job offers are generated for Workers.

var distributionPolicy = await administrationClient.CreateDistributionPolicyAsync(
    new CreateDistributionPolicyOptions(
        distributionPolicyId: "Longest_Idle_45s_Min1Max10",
        offerExpiresAfter: TimeSpan.FromSeconds(45),
        mode: new LongestIdleMode { MinConcurrentOffers = 1, MaxConcurrentOffers = 10 })
    {
        Name = "Longest Idle matching with a 45s offer expiration; min 1, max 10 offers",
    });

var queue = await administrationClient.CreateQueueAsync(
    new CreateQueueOptions(
        queueId: "XBOX_DEFAULT_QUEUE", 
        distributionPolicyId: distributionPolicy.Value.Id)
    {
        Name = "XBOX Default Queue"
    });
const distributionPolicy = await client.path("/routing/distributionPolicies/{distributionPolicyId}", "Longest_Idle_45s_Min1Max10").patch({
    body: {
        offerExpiresAfterSeconds: 45,
        mode: {
            kind: "longestIdle",
            minConcurrentOffers: 1,
            maxConcurrentOffers: 10
        },
        name: "Longest Idle matching with a 45s offer expiration; min 1, max 10 offers"
    },
    contentType: "application/merge-patch+json"
});

const queue = await client.path("/routing/queues/{queueId}", "XBOX_DEFAULT_QUEUE").patch({
    body: {
        distributionPolicyId: distributionPolicy.body.id,
        name: "XBOX Default Queue"
    },
    contentType: "application/merge-patch+json"
  });

distribution_policy = administration_client.upsert_distribution_policy(
    distribution_policy_id = "Longest_Idle_45s_Min1Max10",
    offer_expires_after = timedelta(seconds = 45),
    mode = LongestIdleMode(min_concurrent_offers = 1, max_concurrent_offers = 10),
    name = "Longest Idle matching with a 45s offer expiration; min 1, max 10 offers"
)

queue = administration_client.upsert_queue(
    queue_id = "XBOX_DEFAULT_QUEUE",
    name = "XBOX Default Queue",
    distribution_policy_id = distribution_policy.id
)
DistributionPolicy distributionPolicy = administrationClient.createDistributionPolicy(new CreateDistributionPolicyOptions(
    "Longest_Idle_45s_Min1Max10",
    Duration.ofSeconds(45),
    new LongestIdleMode().setMinConcurrentOffers(1).setMaxConcurrentOffers(10))
    .setName("Longest Idle matching with a 45s offer expiration; min 1, max 10 offers"));

RouterQueue queue = administrationClient.createQueue(new CreateQueueOptions(
    "XBOX_DEFAULT_QUEUE",
    distributionPolicy.getId())
    .setName("XBOX Default Queue"));

Update a queue

The Job Router SDK will update an existing queue when the UpdateQueueAsync method is called.

queue.Name = "XBOX Updated Queue";
queue.Labels.Add("Additional-Queue-Label", new RouterValue("ChatQueue"));
await administrationClient.UpdateQueueAsync(queue);
await administrationClient.path("/routing/queues/{queueId}", queue.body.id).patch({
    body: {
        name: "XBOX Updated Queue",
        labels: { "Additional-Queue-Label": "ChatQueue" }
    },
    contentType: "application/merge-patch+json"
});
queue.name = "XBOX Updated Queue"
queue.labels["Additional-Queue-Label"] = "ChatQueue"
administration_client.upsert_queue(queue.id, queue)
queue.setName("XBOX Updated Queue");
queue.setLabels(Map.of("Additional-Queue-Label", new RouterValue("ChatQueue")));
administrationClient.updateQueue(queue.getId(), BinaryData.fromObject(queue), null);

Delete a queue

To delete a queue using the Job Router SDK, call the DeleteQueue method passing the queue ID.

await administrationClient.DeleteQueueAsync(queue.Value.Id);
await client.path("/routing/queues/{queueId}", queue.body.id).delete();
administration_client.delete_queue(queue.id)
administrationClient.deleteQueue(queue.getId());

Note

To delete a queue you must make sure there are no active jobs assigned to it. Additionally, make sure there are no references to the queue in any classification policies.