1 | var CRON = require('cron').CronJob; |
||
2 | |||
3 | // ------------------------------------------ |
||
4 | // CONSTRUCTOR |
||
5 | // ------------------------------------------ |
||
6 | |||
7 | var init = function(){ |
||
8 | info('Starting CRONManager ...'); |
||
9 | return CRONManager; |
||
10 | } |
||
11 | |||
12 | /** |
||
13 | * Starting all jobs from properties |
||
14 | */ |
||
15 | var start = function(){ |
||
16 | var plugins = SARAH.PluginManager.getList(); |
||
0 ignored issues
–
show
|
|||
17 | for (var i = 0 ; i < plugins.length ; i++){ |
||
18 | var plugin = plugins[i]; |
||
19 | if (!plugin.cron) continue; |
||
0 ignored issues
–
show
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later. Consider: if (a > 0)
b = 42;
If you or someone else later decides to put another statement in, only the first statement will be executed. if (a > 0)
console.log("a > 0");
b = 42;
In this case the statement if (a > 0) {
console.log("a > 0");
b = 42;
}
ensures that the proper code will be executed conditionally no matter how many statements are added or removed. ![]() |
|||
20 | job(plugin); |
||
21 | } |
||
22 | } |
||
23 | |||
24 | var job = function(plugin) { |
||
25 | if (!plugin.cron.time){ return warn('Missing cron time table');} |
||
26 | info("Starting new job %s with cron %s", plugin.name, plugin.cron.time); |
||
27 | |||
28 | // Build callback |
||
29 | var next = function(data){ |
||
30 | if (!data){ return; } |
||
31 | if (data.error){ SARAH.speak(tts); } |
||
0 ignored issues
–
show
The variable
SARAH seems to be never declared. If this is a global, consider adding a /** global: SARAH */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
32 | |||
33 | var tts = SARAH.ScriptManager.speak(data.tts); |
||
34 | if (tts){ SARAH.speak(tts); } |
||
35 | |||
36 | SARAH.RuleEngine.dispatch(plugin.name, data); |
||
37 | } |
||
38 | |||
39 | // Create job |
||
40 | var job = new CRON({ |
||
0 ignored issues
–
show
|
|||
41 | cronTime: plugin.cron.time, |
||
42 | onTick: function() { |
||
43 | info('Cron: %s', plugin.name); |
||
44 | plugin.getInstance().cron(next, plugin.cron, SARAH); |
||
0 ignored issues
–
show
The variable
SARAH seems to be never declared. If this is a global, consider adding a /** global: SARAH */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
45 | }, |
||
46 | start: true |
||
47 | }); |
||
48 | |||
49 | // Run once |
||
50 | plugin.getInstance().cron(next, plugin.cron, SARAH); |
||
0 ignored issues
–
show
|
|||
51 | } |
||
52 | |||
53 | // ------------------------------------------ |
||
54 | // PUBLIC |
||
55 | // ------------------------------------------ |
||
56 | |||
57 | var CRONManager = { |
||
58 | 'init' : init, |
||
59 | 'start': start |
||
60 | } |
||
61 | |||
62 | // Exports Manager |
||
63 | exports.init = CRONManager.init; |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.