Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 161 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@
"test": "mocha 'dist/test/**/*.test.js'"
},
"dependencies": {
"@azure/functions": "^4.0.0-alpha.2"
"@azure/functions": "^4.0.0-alpha.2",
"durable-functions": "^2.0.2"
},
"devDependencies": {
"@types/chai": "^4.0.0",
"@types/mocha": "^9.0.0",
"@types/node": "^18.0.0",
"chai": "^4.0.0",
"func-cli-nodejs-v4": "4.0.4764",
"mocha": "^9.0.0",
"typescript": "^4.0.0",
"func-cli-nodejs-v4": "4.0.4764"
"typescript": "^4.0.0"
},
"main": "dist/src/index.js"
}
}
51 changes: 51 additions & 0 deletions src/functions/durable-generic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { app, HttpRequest, input, InvocationContext, trigger } from "@azure/functions";
import * as df from "durable-functions";

app.generic('DurableFunctionsOrchestratorJS', {
trigger: trigger.generic({
type: 'orchestrationTrigger'
}),
handler: df.orchestrator(function* (context) {
const outputs = [];
outputs.push(yield context.df.callActivity("Hello", "Tokyo"));
outputs.push(yield context.df.callActivity("Hello", "Seattle"));
outputs.push(yield context.df.callActivity("Hello", "Cairo"));

return outputs;
})
})

app.generic('Hello', {
trigger: trigger.generic({
type: 'activityTrigger',
}),
handler: async function(context: InvocationContext, name: string): Promise<string> {
return `Hello ${name}`
}
})

const clientInput = input.generic({
type: 'orchestrationClient'
});

app.generic('DurableFunctionsHttpStart', {
trigger: trigger.generic({
type: 'httpTrigger',
authLevel: 'function',
route: 'orchestrators/{functionName}',
methods: [
'post', 'get'
],
}),
extraInputs: [clientInput],
return: {name: "$return", type:'http'},
handler: async function (context: InvocationContext, req: HttpRequest): Promise<any> {
// @ts-expect-error: whatever
const client = df.getClient(context, clientInput);
const instanceId = await client.startNew(req.params.functionName, undefined, req.body);

context.log(`Started orchestration with ID = '${instanceId}'.`);

return client.createCheckStatusResponse(req, instanceId);
}
})
6 changes: 2 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@ app.timer('timerTrigger1', {
handler: (context: InvocationContext, myTimer: Timer) => {
var timeStamp = new Date().toISOString();
context.log('The current time is: ', timeStamp);
}
});


}
});