-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy path08-while.js
66 lines (54 loc) · 1.7 KB
/
08-while.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
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 GetIncrement extends workflow_es.StepBody {
run(context) {
this.increment = 1;
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 While_Workflow {
constructor() {
this.id = "while-sample";
this.version = 1;
}
build(builder) {
builder
.startWith(SayHello)
.while((data) => data.counter < 3).do((then) => then
.startWith(GetIncrement)
.output((step, data) => data.counter += step.increment)
.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(While_Workflow);
await host.start();
let id = await host.startWorkflow("while-sample", 1, { counter: 0 });
console.log("Started workflow: " + id);
}
main();