From 77f0f159ab1d1648799434c5757b1b741c69a777 Mon Sep 17 00:00:00 2001 From: vjrj Date: Sat, 17 Mar 2018 02:03:26 +0100 Subject: [PATCH] Added cron (wp) --- .meteor/packages | 1 + .meteor/versions | 1 + imports/startup/server/cron.js | 61 +++++++++++++++++++++++++++++++++ imports/startup/server/index.js | 1 + 4 files changed, 64 insertions(+) create mode 100644 imports/startup/server/cron.js diff --git a/.meteor/packages b/.meteor/packages index 81799c5..162e321 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -62,3 +62,4 @@ arkham:comments-ui facts gadicohen:sitemaps nspangler:autoreconnect +saucecode:timezoned-synced-cron diff --git a/.meteor/versions b/.meteor/versions index 0059a9c..3cc41bd 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -116,6 +116,7 @@ reload@1.1.11 retry@1.0.9 reywood:publish-composite@1.5.2 routepolicy@1.0.12 +saucecode:timezoned-synced-cron@1.2.11 selaias:cookie-consent@0.4.0 service-configuration@1.0.11 session@1.1.7 diff --git a/imports/startup/server/cron.js b/imports/startup/server/cron.js new file mode 100644 index 0000000..54de47a --- /dev/null +++ b/imports/startup/server/cron.js @@ -0,0 +1,61 @@ +/* global SyncedCron */ + +import { Meteor } from 'meteor/meteor'; + +// https://github.com/thesaucecode/meteor-synced-cron/ + +Meteor.startup(() => { + SyncedCron.config({ + // Log job run details to console + log: true + + // Use a custom logger function (defaults to Meteor's logging package) + // logger: null + + // Name of collection to use for synchronisation and logging + // collectionName: 'cronHistory', + + // Default to localTime + // Options: 'utc', 'localtime', or specific timezones 'America/New_York' + // Will be applied to jobs with no timezone defined + // timezone: 'utc', + + /* + TTL in seconds for history records in collection to expire + NOTE: Unset to remove expiry but ensure you remove the index from + mongo by hand + + ALSO: SyncedCron can't use the `_ensureIndex` command to modify + the TTL index. The best way to modify the default value of + `collectionTTL` is to remove the index by hand (in the mongo shell + run `db.cronHistory.dropIndex({startedAt: 1})`) and re-run your + project. SyncedCron will recreate the index with the updated TTL. + */ + // 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 => + // 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/ + parser.text('at 9:15 am also at 15:15 pm also at 22:00 pm'), + job: () => { + // console.log('cron is working'); + /* console.log(this.userID) // Context Object becomes this argument + * console.log(this.magic) / + * var numbersCrunched = CrushSomeNumbers(); + * return numbersCrunched; */ + } + }); + + SyncedCron.start(); +}); diff --git a/imports/startup/server/index.js b/imports/startup/server/index.js index 6c5be88..0fd20ce 100644 --- a/imports/startup/server/index.js +++ b/imports/startup/server/index.js @@ -13,3 +13,4 @@ import './sitemaps'; import './subsUnion'; import './prerender'; import './feedback'; +import './cron';