本指南會列出觀察作業路由器供應項目所需的步驟。 其中也概述如何接受或拒絕作業供應項目。
必要條件
- 具有有效訂用帳戶的 Azure 帳戶。 免費建立 Azure 帳戶。
- 已部署的 Azure 通訊服務資源。 建立通訊服務資源。
- 選擇性:完成快速入門以開始使用工作路由器。
接受作業供應項目
建立工作之後,請觀察工作者邀約發出的事件,其中包含工作者識別碼和工作邀約識別碼。 工作者可以使用 SDK 接受工作邀約。 一旦接受邀約,工作就會指派給工作者,且工作的狀態會更新為 assigned
。
// Event handler logic omitted
var accept = await client.AcceptJobOfferAsync(offerIssuedEvent.Data.WorkerId, offerIssuedEvent.Data.OfferId);
// Event handler logic omitted
const accept = await client.path("/routing/workers/{workerId}/offers/{offerId}:accept",
offerIssuedEvent.data.workerId, offerIssuedEvent.data.offerId).post();
# Event handler logic omitted
accept = client.accept_job_offer(offerIssuedEvent.data.worker_id, offerIssuedEvent.data.offer_id)
// Event handler logic omitted
AcceptJobOfferResult accept = client.acceptJobOffer(offerIssuedEvent.getData().getWorkerId(), offerIssuedEvent.getData().getOfferId());
拒絕作業供應項目
工作者可以使用 SDK 拒絕工作邀約。 一旦拒絕邀約,工作就會提供給下一個合格的工作者。 工作不會提供給曾拒絕工作的相同工作者,除非該工作者已取消註冊並重新註冊。
// Event handler logic omitted
await client.DeclineJobOfferAsync(new DeclineJobOfferOptions(workerId: offerIssuedEvent.Data.WorkerId,
offerId: offerIssuedEvent.Data.OfferId));
// Event handler logic omitted
await client.path("/routing/workers/{workerId}/offers/{offerId}:decline",
offerIssuedEvent.data.workerId, offerIssuedEvent.data.offerId).post();
# Event handler logic omitted
client.decline_job_offer(offerIssuedEvent.data.worker_id, offerIssuedEvent.data.offer_id)
// Event handler logic omitted
client.declineJobOffer(offerIssuedEvent.getData().getWorkerId(), offerIssuedEvent.getData().getOfferId());
一段時間後重試邀約
在某些情況下,工作者可能會想要在一段時間後自動重試邀約。 例如,工作者可以在 5 分鐘後重試邀約。 若要執行此流程,工作者可以使用 SDK 拒絕邀約,並指定 retryOfferAfter
屬性。
// Event handler logic omitted
await client.DeclineJobOfferAsync(new DeclineJobOfferOptions(workerId: offerIssuedEvent.Data.WorkerId,
offerId: offerIssuedEvent.Data.OfferId)
{
RetryOfferAt = DateTimeOffset.UtcNow.AddMinutes(5)
});
// Event handler logic omitted
await client.path("/routing/workers/{workerId}/offers/{offerId}:decline",
offerIssuedEvent.data.workerId, offerIssuedEvent.data.offerId).post({
body: {
retryOfferAt: new Date(Date.now() + 5 * 60 * 1000)
}
});
# Event handler logic omitted
client.decline_job_offer(
worker_id = offerIssuedEvent.data.worker_id,
offer_id = offerIssuedEvent.data.offer_id,
retry_offer_at = datetime.utcnow() + timedelta(minutes = 5))
// Event handler logic omitted
client.declineJobOffer(
offerIssuedEvent.getData().getWorkerId(),
offerIssuedEvent.getData().getOfferId(),
new RequestOptions().setBody(BinaryData.fromObject(
new DeclineJobOfferOptions().setRetryOfferAt(OffsetDateTime.now().plusMinutes(5)))));
完成工作
一旦工作者完成與工作相關聯的事務 (例如完成通話),我們就會完成工作,這時狀態會更新為 completed
。
await routerClient.CompleteJobAsync(new CompleteJobOptions(jobId: accept.Value.JobId, assignmentId: accept.Value.AssignmentId));
await client.path("/routing/jobs/{jobId}/assignments/{assignmentId}:complete", accept.body.jobId, accept.body.assignmentId).post();
router_client.complete_job(job_id = job.id, assignment_id = accept.assignment_id)
routerClient.completeJobWithResponse(accept.getJobId(), accept.getAssignmentId(), null);
關閉工作
工作者準備好要接受新工作之後,工作者應關閉工作,這時狀態會更新為 closed
。 工作者可以選擇性地提供處置代碼,指出工作的結果。
await routerClient.CloseJobAsync(new CloseJobOptions(jobId: accept.Value.JobId, assignmentId: accept.Value.AssignmentId) {
DispositionCode = "Resolved"
});
await client.path("/routing/jobs/{jobId}/assignments/{assignmentId}:close", accept.body.jobId, accept.body.assignmentId).post({
body: {
dispositionCode: "Resolved"
}
});
router_client.close_job(job_id = job.id, assignment_id = accept.assignment_id, disposition_code = "Resolved")
routerClient.closeJobWithResponse(accept.getJobId(), accept.getAssignmentId(),
new RequestOptions().setBody(BinaryData.fromObject(new CloseJobOptions().setDispositionCode("Resolved"))));