@@ -27,7 +27,12 @@ module.exports = NodeHelper.create({
2727 return true ;
2828 }
2929
30- if ( notification === "SET_SCHEDULE_MODULE" ) {
30+ if ( notification === "REMOVE_ALL_SCHEDULES" ) {
31+ console . log ( this . name + ' is removing all schedules' ) ;
32+ this . stopAllCronJobs ( ) ;
33+ }
34+
35+ if ( notification === "CREATE_MODULE_SCHEDULE" ) {
3136 module = payload ;
3237 if ( ! module . schedule . hasOwnProperty ( 'from' ) || ! module . schedule . hasOwnProperty ( 'from' ) ) {
3338 console . log ( this . name + ' cannot schedule the module ' + module . name + ' - check module_schedule' ) ;
@@ -46,8 +51,9 @@ module.exports = NodeHelper.create({
4651 return false ;
4752 }
4853
54+ this . cronJobs . push ( { module : module , showJob : showJob , hideJob : hideJob } ) ;
55+
4956 var now = new Date ( ) ;
50- console . log ( 'Current date: ' + now ) ;
5157 if ( showJob . nextDate ( ) . toDate ( ) > now && hideJob . nextDate ( ) . toDate ( ) > showJob . nextDate ( ) . toDate ( ) ) {
5258 console . log ( this . name + ' is hiding ' + module . name ) ;
5359 this . sendSocketNotification ( 'HIDE_MODULE' , module . id ) ;
@@ -60,6 +66,27 @@ module.exports = NodeHelper.create({
6066
6167 }
6268 } ,
69+
70+ stopAllCronJobs : function ( ) {
71+ for ( var i = 0 ; i < this . cronJobs . length ; i ++ ) {
72+ var cronJob = this . cronJobs [ i ] ;
73+ if ( typeof cronJob . showJob === 'object' ) {
74+ this . stopCronJob ( cronJob . showJob ) ;
75+ }
76+ if ( typeof cronJob . hideJob === 'object' ) {
77+ this . stopCronJob ( cronJob . hideJob ) ;
78+ }
79+ }
80+ this . cronJobs . length = 0 ;
81+ } ,
82+
83+ stopCronJob : function ( cronJob ) {
84+ try {
85+ cronJob . stop ( ) ;
86+ } catch ( ex ) {
87+ console . log ( this . name + ' could not stop cronJob' ) ;
88+ }
89+ } ,
6390
6491 createCronJobForModule : function ( module , type ) {
6592 var self = this ;
0 commit comments