Adds support for PushScheduling (#3722)

* Add support for push scheduling

Add a configuration flag on the server to handle the availability of
push scheduling.

* Update push controller to skip sending only if scheduling is configured

Only skip push sending if scheduling is configured

* Update bad conventions

* Add CLI definitions for push scheduling

* Adds tests for pushTime

* Adds test for scheduling

* nits

* Test for not scheduled
This commit is contained in:
Florent Vilmart
2017-04-15 17:20:55 -04:00
committed by GitHub
parent 302a0dda73
commit 907b160fc7
7 changed files with 186 additions and 8 deletions

View File

@@ -110,6 +110,18 @@ export function pushStatusHandler(config, objectId = newObjectId()) {
const handler = statusHandler(PUSH_STATUS_COLLECTION, database);
const setInitial = function(body = {}, where, options = {source: 'rest'}) {
const now = new Date();
let pushTime = new Date();
let status = 'pending';
if (body.hasOwnProperty('push_time')) {
if (config.hasPushScheduledSupport) {
pushTime = body.push_time;
status = 'scheduled';
} else {
logger.warn('Trying to schedule a push while server is not configured.');
logger.warn('Push will be sent immediately');
}
}
const data = body.data || {};
const payloadString = JSON.stringify(data);
let pushHash;
@@ -123,13 +135,13 @@ export function pushStatusHandler(config, objectId = newObjectId()) {
const object = {
objectId,
createdAt: now,
pushTime: now.toISOString(),
pushTime: pushTime.toISOString(),
query: JSON.stringify(where),
payload: payloadString,
source: options.source,
title: options.title,
expiry: body.expiration_time,
status: "pending",
status: status,
numSent: 0,
pushHash,
// lockdown!