-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy path09-if.js
72 lines (62 loc) · 2.12 KB
/
09-if.js
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
61
62
63
64
65
66
67
68
69
70
71
72
const workflow_es = require("workflow-es");
const workflow_mongo = require("workflow-es-mongodb");
class SayHello extends workflow_es.StepBody {
run(context) {
console.log("Hello");
return workflow_es.ExecutionResult.next();
}
}
class PrintMessage extends workflow_es.StepBody {
run(context) {
console.log(this.message);
return workflow_es.ExecutionResult.next();
}
}
class DoSomething extends workflow_es.StepBody {
run(context) {
console.log("Doing something...");
return workflow_es.ExecutionResult.next();
}
}
class SayGoodbye extends workflow_es.StepBody {
run(context) {
console.log("Bye");
return workflow_es.ExecutionResult.next();
}
}
class If_Workflow {
constructor() {
this.id = "if-sample";
this.version = 1;
}
build(builder) {
builder
.startWith(SayHello)
.if((data) => data.value > 3).do((then) => then
.startWith(PrintMessage)
.input((step, data) => step.message = "Value is greater than 3")
.then(DoSomething))
.if((data) => data.value > 6).do((then) => then
.startWith(PrintMessage)
.input((step, data) => step.message = "Value is greater than 6")
.then(DoSomething))
.if((data) => data.value == 5).do((then) => then
.startWith(PrintMessage)
.input((step, data) => step.message = "Value is 5")
.then(DoSomething))
.then(SayGoodbye);
}
}
async function main() {
var config = workflow_es.configureWorkflow();
//config.useLogger(new workflow_es.ConsoleLogger());
//let mongoPersistence = new workflow_mongo.MongoDBPersistence("mongodb://127.0.0.1:27017/workflow-node");
//await mongoPersistence.connect;
//config.usePersistence(mongoPersistence);
var host = config.getHost();
host.registerWorkflow(If_Workflow);
await host.start();
let id = await host.startWorkflow("if-sample", 1, { value: 5 });
console.log("Started workflow: " + id);
}
main();