-
Notifications
You must be signed in to change notification settings - Fork 2
/
workflowCreation.mjs
60 lines (57 loc) · 1.61 KB
/
workflowCreation.mjs
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import {
orkesConductorClient,
WorkflowExecutor,
workflow,
waitTaskDuration,
generateInlineTask,
switchTask,
terminateTask,
} from "@io-orkes/conductor-javascript";
const createCheckoutWorkflow = () =>
workflow(`${process.env.CHECKOUT_WF_NAME || "MyCheckout2"}`, [
waitTaskDuration("confirmation_wait", "15 seconds"),
generateInlineTask({
name: "check_credit",
inputParameters: {
products: "${workflow.input.products}",
totalCredit: "${workflow.input.availableCredit}",
expression: function ($) {
return function () {
var totaAmount = 0;
for (var i = 0; i < $.products.length; i++) {
totaAmount = $.products[i].price;
}
return totaAmount > $.totalCredit ? "noCredit" : "hasCredit";
};
},
},
}),
switchTask("switch_has_credit", "${check_credit_ref.output.result}", {
noCredit: [
terminateTask(
"termination_noCredit",
"FAILED",
"User has no credit to complete"
),
],
hasCredit: [
terminateTask(
"termination_successfull",
"COMPLETED",
"User completed checkout successfully"
),
],
}),
]);
export const playConfig = {
keyId: process.env.KEY,
keySecret:process.env.SECRET,
serverUrl: `${process.env.SERVER_URL}`,
};
(async () => {
const clientPromise = orkesConductorClient(playConfig);
const client = await clientPromise;
const executor = new WorkflowExecutor(client);
const wf = createCheckoutWorkflow();
executor.registerWorkflow(true, wf);
})();