Failed Conditions
Push — master ( c3e11c...1d8d9e )
by Yo
02:09 queued 37s
created

server/cron.js (4 issues)

Labels
Severity
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
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.

Loading history...
17
  for (var i = 0 ; i < plugins.length ; i++){
18
    var plugin = plugins[i]; 
19
    if (!plugin.cron) continue;
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 tts seems to be never initialized.
Loading history...
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.

Loading history...
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({
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.

Loading history...
45
    },
46
    start: true
47
  });
48
  
49
  // Run once
50
  plugin.getInstance().cron(next, plugin.cron, SARAH);
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;