工作路由器背景工作角色容量
設定背景工作角色時,我們想要提供一種方式來指定背景工作角色一次可從各種頻道處理的工作數目。 這是透過指定背景工作角色總容量並針對每個通到指派每個工作的成本來進行設定。
範例: 可以處理一個語音工作或最多五個聊天工作的背景工作角色
在此範例中,我們會設定總容量為 100 的背景工作角色,並將語音頻道設定為每個工作取用 100 個容量,而聊天頻道則為每個工作取用 20 個容量。 此設定表示背景工作角色可以一次處理一個語音工作,或同時處理最多五個聊天工作。 如果背景工作角色正在處理一或多個聊天工作,則背景工作角色必須等到這些聊天工作完成,才能接受任何語音工作。 如果背景工作角色正在處理語音工作,則背景工作必須等到語音工作完成,才能接受任何聊天工作。
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))));
範例: 可以同時處理一個語音工作和最多兩個聊天工作和兩個電子郵件工作的背景工作角色
在此範例中,背景工作角色的容量總計設定為 100。 接下來,語音頻道會設定為每個工作取用 60 個容量,而聊天和電子郵件頻道則每個頻道每個工作會取用 10 個容量,且將 maxNumberOfJobs
設定為兩個。 此設定表示背景工作角色可以一次處理一個語音工作,或同時處理最多兩個聊天工作和兩個電子郵件工作。 由於聊天和電子郵件頻道的 maxNumberOfJobs
已設定為兩個,這些頻道最多可取用 40 個容量。 因此,背景工作角色一律可以處理最多一個語音工作。 語音頻道比其他頻道「優先」。
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))));