Skip to content

Commit b1e2339

Browse files
committedFeb 29, 2016
workflow execution stats
1 parent 68437ae commit b1e2339

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed
 

‎index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ var workflow = {
178178

179179

180180
return function execute(done) {
181-
181+
var wfStartTime = new Date().getTime()
182182

183183
if (!checkCondition(context))
184184
return done()
@@ -266,6 +266,9 @@ var workflow = {
266266
}
267267

268268
debug("Finished executing WF %s", getStepName(workflowDefinition))
269+
if (context.$$$stats) {
270+
context.$$$stats.push(getStepName(workflowDefinition) + " execution time: " + (new Date().getTime() - wfStartTime) +"ms")
271+
}
269272
var originalDone = context.originalTerminate || done;
270273
var donePosition = context.completionStack.indexOf(originalDone);
271274
context.completionStack.splice(donePosition, 1)

‎test/workflow-stats.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
var worksmith = require('..')
2+
var assert = require('assert')
3+
4+
describe("workflow status", function() {
5+
it("should be created", function(done) {
6+
this.slow()
7+
var wf = worksmith([
8+
{
9+
name:"t1",
10+
taskName:"t1",
11+
task: function(def) {
12+
return function build(context) {
13+
return function execute(d) {
14+
15+
//console.log("d1")
16+
setTimeout(function() {
17+
d()
18+
}, 500)
19+
}
20+
}
21+
}
22+
},
23+
{
24+
taskName:"t2",
25+
name: "t2",
26+
task: function(def) {
27+
return function build(context) {
28+
return function execute(d) {
29+
//console.log("d2")
30+
setTimeout(function() {
31+
d()
32+
}, 500)
33+
}
34+
}
35+
}
36+
}
37+
38+
]);
39+
var before = Date.now()
40+
var ctx = { $$$stats: []}
41+
wf(ctx, function(err, result, ctx) {
42+
assert(ctx.$$$stats.join("").match(/t1 execution time: [0-9]{3}mst2 execution time: [0-9]{3}mssequence execution time: [0-9]{4}ms/))
43+
done(null, result)
44+
})
45+
})
46+
})

0 commit comments

Comments
 (0)
Please sign in to comment.