Cron tweet tasks enabled/disabled

This commit is contained in:
vjrj 2018-04-01 16:37:59 +02:00
parent 21531d1fd2
commit 4dfdd48e6a
2 changed files with 41 additions and 30 deletions

View file

@ -36,46 +36,55 @@ Meteor.startup(() => {
// collectionTTL: 172800 // collectionTTL: 172800
}); });
SyncedCron.add({ const esEn = Meteor.settings.private.twitter.es.enabled;
name: 'Check for fires stats in Spain and tweet about', const enEn = Meteor.settings.private.twitter.en.enabled;
timezone: 'Europe/Madrid',
// Optionally set a positive offset if you wish to 'snooze' a schedule if (esEn) {
// offset: 30 * 60 * 100, SyncedCron.add({
// context: { name: 'Check for fires stats in Spain and tweet about',
// userID: 'xyz' timezone: 'Europe/Madrid',
// }, // Optionally set a positive offset if you wish to 'snooze' a schedule
schedule: (parser) => { // offset: 30 * 60 * 100,
// context: {
// userID: 'xyz'
// },
schedule: (parser) => {
// this.magic = true; // Context is accesible here as this context. // this.magic = true; // Context is accesible here as this context.
// parser is a later.parse object // parser is a later.parse object
// return parser.text('every 2 minutes'); // return parser.text('every 2 minutes');
// http://bunkat.github.io/later/ // http://bunkat.github.io/later/
const sched = parser.text(Meteor.settings.private.twitter.es.when); const sched = parser.text(Meteor.settings.private.twitter.es.when);
if (sched.error !== -1) { if (sched.error !== -1) {
console.error(`Twitter cron 'when' field parsed with errors: ${sched.error}`); console.error(`Twitter cron 'when' field parsed with errors: ${sched.error}`);
} }
return sched; return sched;
}, },
job: () => tweetIberiaFires() job: () => tweetIberiaFires()
/* console.log('cron is working'); /* console.log('cron is working');
* console.log(this.userID) // Context Object becomes this argument * console.log(this.userID) // Context Object becomes this argument
* console.log(this.magic) / * console.log(this.magic) /
* var numbersCrunched = CrushSomeNumbers(); * var numbersCrunched = CrushSomeNumbers();
* return numbersCrunched; * return numbersCrunched;
return tweetFires(); */ return tweetFires(); */
}); });
}
SyncedCron.add({ if (enEn) {
name: 'Check for fires stats in Europe and tweet about', SyncedCron.add({
timezone: 'Europe/Madrid', name: 'Check for fires stats in Europe and tweet about',
schedule: (parser) => { timezone: 'Europe/Madrid',
const sched = parser.text(Meteor.settings.private.twitter.en.when); schedule: (parser) => {
if (sched.error !== -1) { const sched = parser.text(Meteor.settings.private.twitter.en.when);
console.error(`Twitter cron 'when' field parsed with errors: ${sched.error}`); if (sched.error !== -1) {
} console.error(`Twitter cron 'when' field parsed with errors: ${sched.error}`);
return sched; }
}, return sched;
job: () => tweetEuropeFires() },
}); job: () => tweetEuropeFires()
});
}
SyncedCron.start(); if (esEn || enEn) {
SyncedCron.start();
}
}); });

View file

@ -33,6 +33,7 @@
"ironPassword": "SomePasswordAlLeast32LongYouKnowHowToCount", "ironPassword": "SomePasswordAlLeast32LongYouKnowHowToCount",
"twitter": { "twitter": {
"es": { "es": {
"enabled": true,
"comment": "using later.js", "comment": "using later.js",
"when": "at 9:15 am also at 3:15 pm also at 10:00 pm", "when": "at 9:15 am also at 3:15 pm also at 10:00 pm",
"consumer_key": "...", "consumer_key": "...",
@ -41,6 +42,7 @@
"access_token_secret": "..." "access_token_secret": "..."
}, },
"en": { "en": {
"enabled": true,
"comment": "using later.js", "comment": "using later.js",
"when": "at 9:15 am also at 3:15 pm also at 10:00 pm", "when": "at 9:15 am also at 3:15 pm also at 10:00 pm",
"consumer_key": "...", "consumer_key": "...",