Cron Jobs
NotifyBC runs several cron jobs described below. These jobs are controlled by sub-properties defined in config object cron. To change config, create the object and properties in file src/config.local.js.
By default cron jobs are enabled. In a multi-node deployment, cron jobs should only run on the primary node to ensure single execution.
All cron jobs have a property named timeSpec with the value of a space separated fields conforming to unix crontab format with an optional left-most seconds field. See allowed ranges of each field.
Purge Data
This cron job purges old notifications, subscriptions and notification bounces. The default frequency of cron job and retention policy are defined by cron.purgeData config object in file src/config.ts
module.exports = {
cron: {
purgeData: {
// daily at 1am
timeSpec: '0 0 1 * * *',
pushNotificationRetentionDays: 30,
expiredInAppNotificationRetentionDays: 30,
nonConfirmedSubscriptionRetentionDays: 30,
deletedBounceRetentionDays: 30,
expiredAccessTokenRetentionDays: 30,
defaultRetentionDays: 30,
},
},
};
where
- pushNotificationRetentionDays: the retention days of push notifications
- expiredInAppNotificationRetentionDays: the retention days of expired inApp notifications
- nonConfirmedSubscriptionRetentionDays: the retention days of non-confirmed subscriptions, i.e. all unconfirmed and deleted subscriptions
- deletedBounceRetentionDays: the retention days of deleted notification bounces
- expiredAccessTokenRetentionDays: the retention days of expired access tokens
- defaultRetentionDays: if any of the above retention day config item is omitted, default retention days is used as fall back.
To change a config item, set the config item in file src/config.local.js. For example, to run cron jobs at 2am daily, add following object to src/config.local.js
module.exports = {
cron: {
purgeData: {
timeSpec: '0 0 2 * * *',
},
},
};
Dispatch Live Notifications
This cron job sends out future-dated notifications when the notification becomes current. The default config is defined by cron.dispatchLiveNotifications config object in file src/config.ts
module.exports = {
cron: {
dispatchLiveNotifications: {
// minutely
timeSpec: '0 * * * * *',
},
},
};
Check Rss Config Updates
This cron job monitors RSS feed notification dynamic config items. If a config item is created, updated or deleted, the cron job starts, restarts, or stops the RSS-specific cron job. The default config is defined by cron.checkRssConfigUpdates config object in file src/config.ts
module.exports = {
cron: {
checkRssConfigUpdates: {
// minutely
timeSpec: '0 * * * * *',
},
},
};
Note timeSpec doesn't control the RSS poll frequency (which is defined in dynamic configs and is service specific), instead it only controls the frequency to check for dynamic config changes.
Delete Notification Bounces
This cron job deletes notification bounces if the latest notification is deemed delivered successfully. The criteria of successful delivery are
- No bounce received since the latest notification started dispatching, and
- a configured time span has lapsed since the latest notification finished dispatching
The default config is defined by cron.deleteBounces config object in file src/config.ts
module.exports = {
cron: {
deleteBounces: {
// hourly
timeSpec: '0 0 * * * *',
minLapsedHoursSinceLatestNotificationEnded: 1,
},
},
};
where
- minLapsedHoursSinceLatestNotificationEnded is the time span
Re-dispatch Broadcast Push Notifications
This cron job re-dispatches a broadcast push notifications when redis cluster fails. It is part of guaranteed broadcast push dispatch processing
The default config is defined by cron.reDispatchBroadcastPushNotifications config object in file src/config.ts
module.exports = {
cron: {
reDispatchBroadcastPushNotifications: {
// minutely
timeSpec: '0 * * * * *',
},
},
};