|
1 |
| -import { HttpRequest, InvocationContext } from '@azure/functions'; |
| 1 | +import { app, HttpRequest, InvocationContext, output, trigger } from '@azure/functions'; |
2 | 2 | import * as df from 'durable-functions';
|
3 |
| -import { DurableOrchestrationClient, IOrchestrationFunctionContext } from 'durable-functions/lib/src/classes'; |
| 3 | +import { IOrchestrationFunctionContext } from 'durable-functions/lib/src/classes'; |
4 | 4 |
|
5 |
| -df.orchestration('DurableFunctionsOrchestratorJS', function* (context: IOrchestrationFunctionContext) { |
6 |
| - const outputs = []; |
7 |
| - outputs.push(yield context.df.callActivity('Hello', 'Tokyo')); |
8 |
| - outputs.push(yield context.df.callActivity('Hello', 'Seattle')); |
9 |
| - outputs.push(yield context.df.callActivity('Hello', 'Cairo')); |
| 5 | +app.generic('DurableFunctionsOrchestratorJS', { |
| 6 | + trigger: df.trigger.orchestration(), |
| 7 | + handler: df.createOrchestrator(function* (context: IOrchestrationFunctionContext) { |
| 8 | + const outputs = []; |
| 9 | + outputs.push(yield context.df.callActivity('Hello', 'Tokyo')); |
| 10 | + outputs.push(yield context.df.callActivity('Hello', 'Seattle')); |
| 11 | + outputs.push(yield context.df.callActivity('Hello', 'Cairo')); |
10 | 12 |
|
11 |
| - return outputs; |
| 13 | + return outputs; |
| 14 | + }) |
12 | 15 | });
|
13 | 16 |
|
14 |
| -df.activity('Hello', (context: InvocationContext, name: string) => { |
15 |
| - return `Hello, ${name}`; |
| 17 | +app.generic('Hello', { |
| 18 | + trigger: df.trigger.activity(), |
| 19 | + handler: async function (context: InvocationContext, name: string): Promise<string> { |
| 20 | + return `Hello ${name}`; |
| 21 | + } |
16 | 22 | });
|
17 | 23 |
|
18 |
| -df.httpClient( |
19 |
| - 'DurableFunctionsHttpStart', |
20 |
| - async (context: InvocationContext, req: HttpRequest, client: DurableOrchestrationClient) => { |
21 |
| - const instanceId = await client.startNew(req.query.get('functionName'), undefined, req.body); |
22 |
| - context.log(`Started orchestration with ID = '${instanceId}'.`); |
| 24 | +const clientInput = df.input.client(); |
| 25 | +app.generic('DurableFunctionsHttpStart', { |
| 26 | + trigger: trigger.http({ |
| 27 | + route: 'orchestrators/{functionName}' |
| 28 | + }), |
| 29 | + extraInputs: [clientInput], |
| 30 | + return: output.http({}), |
| 31 | + handler: async function (context: InvocationContext, req: HttpRequest): Promise<any> { |
| 32 | + const client = df.getClient(context, clientInput); |
| 33 | + const instanceId = await client.startNew(req.params.functionName, undefined, req.body); |
| 34 | + |
| 35 | + context.log(`Started orchestration with ID = ${instanceId}.`); |
| 36 | + |
23 | 37 | return client.createCheckStatusResponse(req, instanceId);
|
24 | 38 | }
|
25 |
| -); |
| 39 | +}); |
0 commit comments