forked from elastic/opbeans-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrewbot.js
65 lines (54 loc) · 1.2 KB
/
brewbot.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
'use strict'
// this worker simulates a background job that uses custom transactions
var apm = require('elastic-apm')
queue(roast)
queue(grind)
queue(boil)
queue(pour)
queue(serve)
function roast () {
apm.startTransaction('Roast beans', 'Brewing Bot')
performSubTask(function () {
apm.endTransaction()
queue(roast)
})
}
function grind () {
apm.startTransaction('Grind beans', 'Brewing Bot')
performSubTask(function () {
apm.endTransaction()
queue(grind)
})
}
function boil () {
apm.startTransaction('Boil water', 'Brewing Bot')
performSubTask(function () {
apm.endTransaction()
queue(boil)
})
}
function pour () {
apm.startTransaction('Pour water', 'Brewing Bot')
performSubTask(function () {
apm.endTransaction()
queue(pour)
})
}
function serve () {
apm.startTransaction('Serve to customer', 'Brewing Bot')
performSubTask(function () {
apm.endTransaction()
queue(serve)
})
}
function performSubTask (cb) {
var trace = apm.buildTrace()
if (trace) trace.start('perform some task')
setTimeout(function () {
if (trace) trace.end()
cb()
}, Math.random() * 1000)
}
function queue (cb) {
setTimeout(cb, Math.random() * 60000 + 10000)
}