Meteor.startup(() => { // Make sure all API backends have bookmark counts Meteor.call('setAllApiBackendBookmarkCounts'); // Make sure all API backends have average ratings Meteor.call('setAllApiBackendAverageRatings'); // Restart all cron worker Meteor.call('restartCron'); SyncedCron.start(); });
export default function () { SyncedCron.config({ log: Meteor.isDevelopment }); }
// we use here percolate:synced-cron package // learn more at: https://atmospherejs.com/percolate/synced-cron 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 using localTime utc: true, /* 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: 'Remove old chat sessions and related messages.',
import { SyncedCron } from 'meteor/percolate:synced-cron'; import { Meteor } from 'meteor/meteor'; import exportClaims from '/imports/api/claims/export_claims.js'; if (!Meteor.settings.private.disableCron) { SyncedCron.add({ name: 'Generate all claims CSV Export', schedule(parser) { return parser.text('every 15 minutes'); }, job() { exportClaims.allClaimsCsv(); }, }); SyncedCron.start(); }
import { Meteor } from 'meteor/meteor'; import { SyncedCron } from 'meteor/percolate:synced-cron'; import Initiatives from '/collections/Initiatives'; import later from 'later'; import moment from 'moment'; import { email } from '../../sendgrid/email'; SyncedCron.config({ collectionName: 'cronCollection' }); SyncedCron.add({ name: "Daily Check Email Digest", schedule: (parser) => { if (Meteor.isProduction) { return parser.text('at 8:00pm'); } else { return parser.text('at 4:00pm'); } }, job: (time) => { const inits = Initiatives.find({userActive: true}).fetch(); const notChecked = []; inits.forEach((init) => { if (init.dailyCheck === false) { notChecked.push(init.name); } }); let htmlString = "<h3>The following Initiatives have not been checked today: </h3><br>" + notChecked.join('<br>') + ""
Meteor.startup(() => { SyncedCron.start(); });
SyncedCron.add({ name: 'Remove expired invitations and expired email verification tokens', schedule(parser) { return parser.text('every 1 minute'); }, job() { const emailVerificationExpirationTimeInHours = 0.03; const emailVerificationExpirationThresholdDate = moment() .subtract(emailVerificationExpirationTimeInHours, 'hours') .toDate(); // get all users with expired invitations Meteor.users.find({ invitationExpirationDate: { $lt: new Date(), }, }, { fields: { _id: 1 } }).forEach(userDoc => Meteor.users.remove({ _id: userDoc._id })); // get all users with expired email verification tokens Meteor.users.find({ 'services.email.verificationTokens.when': { $lt: emailVerificationExpirationThresholdDate, }, 'emails.verified': false, }, { fields: { _id: 1 } }).forEach((userDoc) => { Meteor.users.update({ _id: userDoc._id }, { $unset: { 'services.email': '' } }); }); console.log( 'Expired invitations and expired email verification tokens removed at ', new Date(), ); }, });
import { Meteor } from 'meteor/meteor'; import { SyncedCron } from 'meteor/percolate:synced-cron'; Meteor.startup(() => { SyncedCron.start(); }); SyncedCron.config({ log: false, });
import { Meteor } from 'meteor/meteor' import { SyncedCron } from 'meteor/percolate:synced-cron'; import { Moment } from 'meteor/momentjs:moment' import { dailyUpdate } from './initiativeDailyBreakdownUpdaterFunc' import CampaignInsights from '/collections/CampaignInsights' import Initiatives from '/collections/Initiatives' import InsightsBreakdownsByDays from '/collections/InsightsBreakdownsByDays' import { apiVersion } from '/server/token/token' const later = require('later'); SyncedCron.config({ collectionName: 'cronCollection' }); SyncedCron.add({ name: "Daily Breakdown Updater", schedule: (parser) => { // return parser.text('at 10:42am'); return parser.text('every 4 hours'); }, job: (time) => { const inits = Initiatives.find({userActive: true}).fetch(); let onlyIds = _.map(inits, (el) => { return el.campaign_ids }); // now i'm sitting with all the campaign ID's of the active initiatives let flat = _.flatten(onlyIds);
SyncedCron.add({ name: 'Remove expired email verification tokens', schedule(parser) { return parser.text('every 1 day'); }, job() { const emailVerificationExpirationTimeInDays = Meteor.settings.public.emailVerificationExpirationTimeInDays || 3; const emailVerificationThresholdDate = moment() .subtract(emailVerificationExpirationTimeInDays, 'days') .toDate(); // In case if we'll need to remove users with expired tokens // //get all users with expired invitations // Meteor.users.find({ // invitationExpirationDate: { // $lt: new Date // } // }, { fields: { _id: 1 } }).forEach(userDoc => { // // //Because of meteor's protection remove each user by ID // Meteor.users.remove({ _id: userDoc._id }); // }); // get all users with expired email verification tokens Meteor.users.find({ 'services.email.verificationTokens.when': { $lt: emailVerificationThresholdDate, }, 'emails.verified': false, }, { fields: { _id: 1 } }).forEach((userDoc) => { Meteor.users.update( { _id: userDoc._id }, { multi: true }, { $pull: { 'services.email.verificationTokens': { when: { $lt: emailVerificationThresholdDate } }, }, }, ); }); console.log('Expired email verification tokens removed at', new Date()); }, });
import { Meteor } from 'meteor/meteor'; import { SyncedCron } from 'meteor/percolate:synced-cron'; import Initiatives from '/collections/Initiatives'; import later from 'later'; import moment from 'moment'; SyncedCron.config({ collectionName: 'cronCollection' }); SyncedCron.add({ name: "Reset Daily Check", schedule: (parser) => { // return parser.text('at 4:19pm') return parser.text('at 1:00am'); }, job: (time) => { const inits = Initiatives.find({}).fetch(); inits.forEach((init) => { Initiatives.update({_id: init._id}, {$set: {dailyCheck: false}}); }); } });
// Create unique name for Cron job const uniqueName = `Monitoring: ${apiId}`; // Set time of the monitoring call const cronTime = 'every 1 hour'; // Update api status to 'Loading...' Apis.update(apiId, { $set: { latestMonitoringStatusCode: 0 } }); // Create cron working SyncedCron.add({ name: uniqueName, schedule (parser) { // parser is a later.parse object return parser.text(cronTime); }, job () { // Get API status using http request Meteor.call('getApiStatus', apiId, url, endPoint); }, }); }, stopCron (apiId) { // Make sure apiId is a String check(apiId, String); // Create unique name for Cron job const uniqueName = `Monitoring: ${apiId}`; // Stop Cron job SyncedCron.remove(uniqueName);