Skip to content

Commit b0ef90e

Browse files
Merge pull request #245655 from williamzhao87/patch-3
Update router-quickstart-python.md
2 parents 226aff9 + a1c8b6b commit b0ef90e

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

articles/communication-services/quickstarts/router/includes/router-quickstart-python.md

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,18 @@ pip install azure-communication-jobrouter
4848
Create a new file called `router-quickstart.py` and add the basic program structure.
4949

5050
```python
51-
import os
52-
from datetime import datetime, timedelta
51+
import time
5352
from azure.communication.jobrouter import (
5453
JobRouterClient,
55-
JobRouterAdministrationClient
54+
JobRouterAdministrationClient,
55+
DistributionPolicy,
56+
LongestIdleMode,
57+
RouterQueue,
58+
RouterJob,
59+
RouterWorkerSelector,
60+
LabelOperator,
61+
RouterWorker,
62+
ChannelConfiguration
5663
)
5764

5865
class RouterQuickstart(object):
@@ -70,19 +77,19 @@ Job Router clients can be authenticated using your connection string acquired fr
7077
```python
7178
# Get a connection string to our Azure Communication Services resource.
7279
connection_string = "your_connection_string"
73-
router_admin_client = JobRouterAdministrationClient(connection_string)
74-
router_client = JobRouterClient(connection_string)
80+
router_admin_client = JobRouterAdministrationClient.from_connection_string(conn_str = connection_string)
81+
router_client = JobRouterClient.from_connection_string(conn_str = connection_string)
7582
```
7683

7784
## Create a distribution policy
7885

79-
Job Router uses a distribution policy to decide how Workers will be notified of available Jobs and the time to live for the notifications, known as **Offers**. Create the policy by specifying the **ID**, a **name**, an **offerExpiresAfterUtc**, and a distribution **mode**.
86+
Job Router uses a distribution policy to decide how Workers will be notified of available Jobs and the time to live for the notifications, known as **Offers**. Create the policy by specifying the **distribution_policy_id**, a **name**, an **offer_expires_after_seconds** value, and a distribution **mode**.
8087

8188
```python
8289
distribution_policy = router_admin_client.create_distribution_policy(
83-
distribution_policy_id="distribution-policy-1",
90+
distribution_policy_id ="distribution-policy-1",
8491
distribution_policy = DistributionPolicy(
85-
offer_expires_after = timedelta(minutes = 1),
92+
offer_expires_after_seconds = 60,
8693
mode = LongestIdleMode(),
8794
name = "My distribution policy"
8895
))
@@ -108,14 +115,14 @@ Now, we can submit a job directly to that queue, with a worker selector that req
108115
```python
109116
job = router_client.create_job(
110117
job_id = "job-1",
111-
job = RouterJob(
118+
router_job = RouterJob(
112119
channel_id = "voice",
113120
queue_id = queue.id,
114121
priority = 1,
115122
requested_worker_selectors = [
116123
RouterWorkerSelector(
117124
key = "Some-Skill",
118-
label_operator = LabelOperator.GreaterThan,
125+
label_operator = LabelOperator.GREATER_THAN,
119126
value = 10
120127
)
121128
]
@@ -132,14 +139,15 @@ worker = router_client.create_worker(
132139
router_worker = RouterWorker(
133140
total_capacity = 1,
134141
queue_assignments = {
135-
"queue-1": {}
142+
queue.id: {}
136143
},
137144
labels = {
138-
"Some-Skill": LabelValue(11)
145+
"Some-Skill": 11
139146
},
140147
channel_configurations = {
141148
"voice": ChannelConfiguration(capacity_cost_per_job = 1)
142-
}
149+
},
150+
available_for_offers = True
143151
))
144152
```
145153

@@ -182,6 +190,14 @@ router_client.close_job(job_id = job.id, assignment_id = accept.assignment_id, d
182190
print(f"Worker {worker.id} has closed job {accept.job_id}")
183191
```
184192

193+
## Delete the job
194+
195+
Once the job has been closed, we can delete the job so that we can re-create the job with the same ID if we run this sample again
196+
```python
197+
router_client.delete_job(accept.job_id)
198+
print(f"Deleting {accept.job_id}")
199+
```
200+
185201
## Run the code
186202

187203
To run the code, make sure you are on the directory where your `router-quickstart.py` file is.

0 commit comments

Comments
 (0)