Skip to content

Commit c1f56fc

Browse files
committed
update based on uuf
Signed-off-by: Hannah Hunter <[email protected]>
1 parent 15910e3 commit c1f56fc

1 file changed

Lines changed: 22 additions & 39 deletions

File tree

articles/azure-functions/durable/durable-functions-singletons.md

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ public static async Task<HttpResponseData> RunSingle(
6969
7070
# [JavaScript](#tab/javascript)
7171

72+
> [!NOTE]
73+
> This JavaScript example uses the Node.js programming model v3, which uses *function.json*. If you're using the Node.js programming model v4, use the v4 code-first pattern instead.
74+
7275
**function.json**
7376

7477
```json
@@ -130,57 +133,37 @@ module.exports = async function(context, req) {
130133

131134
# [Python](#tab/python)
132135

133-
**function.json**
134-
135-
```json
136-
{
137-
"bindings": [
138-
{
139-
"authLevel": "function",
140-
"name": "req",
141-
"type": "httpTrigger",
142-
"direction": "in",
143-
"route": "orchestrators/{functionName}/{instanceId}",
144-
"methods": ["post"]
145-
},
146-
{
147-
"name": "starter",
148-
"type": "orchestrationClient",
149-
"direction": "in"
150-
},
151-
{
152-
"name": "$return",
153-
"type": "http",
154-
"direction": "out"
155-
}
156-
]
157-
}
158-
```
159-
160-
**__init__.py**
136+
**function_app.py**
161137

162138
```python
163139
import logging
164140
import azure.functions as func
165141
import azure.durable_functions as df
166142

167-
async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
168-
client = df.DurableOrchestrationClient(starter)
169-
instance_id = req.route_params['instanceId']
170-
function_name = req.route_params['functionName']
143+
app = df.DFApp(http_auth_level=func.AuthLevel.FUNCTION)
144+
145+
@app.route(route="orchestrators/{functionName}/{instanceId}", methods=["POST"])
146+
@app.durable_client_input(client_name="client")
147+
async def http_start_single(req: func.HttpRequest, client):
148+
instance_id = req.route_params["instanceId"]
149+
function_name = req.route_params["functionName"]
171150

172151
existing_instance = await client.get_status(instance_id)
173152

174-
if existing_instance.runtime_status in [df.OrchestrationRuntimeStatus.Completed, df.OrchestrationRuntimeStatus.Failed, df.OrchestrationRuntimeStatus.Terminated, None]:
153+
if not existing_instance or existing_instance.runtime_status in [
154+
df.OrchestrationRuntimeStatus.Completed,
155+
df.OrchestrationRuntimeStatus.Failed,
156+
df.OrchestrationRuntimeStatus.Terminated,
157+
]:
175158
event_data = req.get_body()
176-
instance_id = await client.start_new(function_name, instance_id, event_data)
159+
instance_id = await client.start_new(function_name, instance_id, event_data)
177160
logging.info(f"Started orchestration with ID = '{instance_id}'.")
178161
return client.create_check_status_response(req, instance_id)
179-
else:
180-
return {
181-
'status': 409,
182-
'body': f"An instance with ID '${existing_instance.instance_id}' already exists"
183-
}
162+
163+
return func.HttpResponse(
164+
body=f"An instance with ID '{instance_id}' already exists.",
165+
status_code=409,
166+
)
184167

185168
```
186169

0 commit comments

Comments
 (0)