-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmachine-def.struct.js
78 lines (45 loc) · 1.65 KB
/
machine-def.struct.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
73
74
75
76
77
78
module.exports = {
friendlyName: 'Do something',
description: 'Do a thing (should be <=80 characters written in the imperative mood)',
extendedDescription: 'Longer description. Markdown syntax supported.',
moreInfoUrl: 'http://hello.com',
sideEffects: 'idempotent', // either omit or set as "cacheable" or "idempotent"
habitat: 'sails', // either omit or set as "request" or "sails"
sync: true, // either omit or set as `true`
inputs: {
someInput: require('./input-def.struct')
},
exits: {
someExit: require('./exit-def.struct')
},
fn: function (inputs, exits) {
var _ = require('@sailshq/lodash');
setTimeout(function (){
try {
var luckyNum = Math.random();
if (luckyNum > 0.5) {
throw new Error('whatever');
}
else if (luckyNum < 0.1) {
// Exit `someExit` with no output.
return exits.someExit();
// > NOTE:
// > To send back output, could have done:
// > ```
// > return exits.someExit(luckyNum);
// > ```
// > (^^but if so, we would need to define an `outputExample` in our `someExit` definition!)
}
} catch (e) { return exits.error(e); }
// --• OK so if we made it here, `luckyNum` must be between 0.1 and 0.5 (exclusive).
// Exit `success` with no output.
return exits.success();
// > NOTE:
// > To send back output, could have done:
// > ```
// > return exits.success(luckyNum);
// > ```
// > (^^but if so, we would need to define `success` exit with an `outputExample`!)
}, 500);//</setTimeout>
}
};