diff --git a/imports/startup/server/cron.js b/imports/startup/server/cron.js index e93fc3b..a18cf89 100644 --- a/imports/startup/server/cron.js +++ b/imports/startup/server/cron.js @@ -36,46 +36,55 @@ Meteor.startup(() => { // collectionTTL: 172800 }); - SyncedCron.add({ - name: 'Check for fires stats in Spain and tweet about', - timezone: 'Europe/Madrid', - // Optionally set a positive offset if you wish to 'snooze' a schedule - // offset: 30 * 60 * 100, - // context: { - // userID: 'xyz' - // }, - schedule: (parser) => { + const esEn = Meteor.settings.private.twitter.es.enabled; + const enEn = Meteor.settings.private.twitter.en.enabled; + + if (esEn) { + SyncedCron.add({ + name: 'Check for fires stats in Spain and tweet about', + timezone: 'Europe/Madrid', + // Optionally set a positive offset if you wish to 'snooze' a schedule + // offset: 30 * 60 * 100, + // context: { + // userID: 'xyz' + // }, + schedule: (parser) => { // this.magic = true; // Context is accesible here as this context. // parser is a later.parse object // return parser.text('every 2 minutes'); // http://bunkat.github.io/later/ - const sched = parser.text(Meteor.settings.private.twitter.es.when); - if (sched.error !== -1) { - console.error(`Twitter cron 'when' field parsed with errors: ${sched.error}`); - } - return sched; - }, - job: () => tweetIberiaFires() + const sched = parser.text(Meteor.settings.private.twitter.es.when); + if (sched.error !== -1) { + console.error(`Twitter cron 'when' field parsed with errors: ${sched.error}`); + } + return sched; + }, + job: () => tweetIberiaFires() /* console.log('cron is working'); * console.log(this.userID) // Context Object becomes this argument * console.log(this.magic) / * var numbersCrunched = CrushSomeNumbers(); * return numbersCrunched; return tweetFires(); */ - }); + }); + } - SyncedCron.add({ - name: 'Check for fires stats in Europe and tweet about', - timezone: 'Europe/Madrid', - schedule: (parser) => { - const sched = parser.text(Meteor.settings.private.twitter.en.when); - if (sched.error !== -1) { - console.error(`Twitter cron 'when' field parsed with errors: ${sched.error}`); - } - return sched; - }, - job: () => tweetEuropeFires() - }); + if (enEn) { + SyncedCron.add({ + name: 'Check for fires stats in Europe and tweet about', + timezone: 'Europe/Madrid', + schedule: (parser) => { + const sched = parser.text(Meteor.settings.private.twitter.en.when); + if (sched.error !== -1) { + console.error(`Twitter cron 'when' field parsed with errors: ${sched.error}`); + } + return sched; + }, + job: () => tweetEuropeFires() + }); + } - SyncedCron.start(); + if (esEn || enEn) { + SyncedCron.start(); + } }); diff --git a/settings-development-sample.json b/settings-development-sample.json index dfae0a8..8bfef3e 100644 --- a/settings-development-sample.json +++ b/settings-development-sample.json @@ -33,6 +33,7 @@ "ironPassword": "SomePasswordAlLeast32LongYouKnowHowToCount", "twitter": { "es": { + "enabled": true, "comment": "using later.js", "when": "at 9:15 am also at 3:15 pm also at 10:00 pm", "consumer_key": "...", @@ -41,6 +42,7 @@ "access_token_secret": "..." }, "en": { + "enabled": true, "comment": "using later.js", "when": "at 9:15 am also at 3:15 pm also at 10:00 pm", "consumer_key": "...",