-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathhttpStart.ts
More file actions
36 lines (32 loc) · 1.23 KB
/
httpStart.ts
File metadata and controls
36 lines (32 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import * as df from "durable-functions";
import { app, HttpHandler, HttpRequest, HttpResponse, InvocationContext } from "@azure/functions";
const httpStart: HttpHandler = async (
request: HttpRequest,
context: InvocationContext
): Promise<HttpResponse> => {
const client = df.getClient(context);
const body: unknown = await request.json();
// Get optional version from query parameter
const version = request.query.get("version");
let instanceId: string;
if (version) {
// Override the orchestration version
instanceId = await client.startNew(request.params.orchestratorName, {
input: body,
version: version,
});
context.log(`Started orchestration with ID = '${instanceId}' and version = '${version}'.`);
} else {
// Use defaultVersion from host.json
instanceId = await client.startNew(request.params.orchestratorName, {
input: body,
});
context.log(`Started orchestration with ID = '${instanceId}'.`);
}
return client.createCheckStatusResponse(request, instanceId);
};
app.http("httpStart", {
route: "orchestrators/{orchestratorName}",
extraInputs: [df.input.durableClient()],
handler: httpStart,
});