Adds ability to track sent/failed PerUTCOffset in the PushWorker (#4158)
* Adds ability to track sent/failed PerUTCOffset in the PushWorker - for scheduled push notifications at a certain time, it helps keep track of the state * Makes sure we track it all correctly * Adds to Postgres
This commit is contained in:
@@ -72,20 +72,22 @@ const defaultColumns = Object.freeze({
|
||||
"subtitle": {type:'String'},
|
||||
},
|
||||
_PushStatus: {
|
||||
"pushTime": {type:'String'},
|
||||
"source": {type:'String'}, // rest or webui
|
||||
"query": {type:'String'}, // the stringified JSON query
|
||||
"payload": {type:'String'}, // the stringified JSON payload,
|
||||
"title": {type:'String'},
|
||||
"expiry": {type:'Number'},
|
||||
"status": {type:'String'},
|
||||
"numSent": {type:'Number'},
|
||||
"numFailed": {type:'Number'},
|
||||
"pushHash": {type:'String'},
|
||||
"errorMessage": {type:'Object'},
|
||||
"sentPerType": {type:'Object'},
|
||||
"failedPerType":{type:'Object'},
|
||||
"count": {type:'Number'}
|
||||
"pushTime": {type:'String'},
|
||||
"source": {type:'String'}, // rest or webui
|
||||
"query": {type:'String'}, // the stringified JSON query
|
||||
"payload": {type:'String'}, // the stringified JSON payload,
|
||||
"title": {type:'String'},
|
||||
"expiry": {type:'Number'},
|
||||
"status": {type:'String'},
|
||||
"numSent": {type:'Number'},
|
||||
"numFailed": {type:'Number'},
|
||||
"pushHash": {type:'String'},
|
||||
"errorMessage": {type:'Object'},
|
||||
"sentPerType": {type:'Object'},
|
||||
"failedPerType": {type:'Object'},
|
||||
"sentPerUTCOffset": {type:'Object'},
|
||||
"failedPerUTCOffset": {type:'Object'},
|
||||
"count": {type:'Number'}
|
||||
},
|
||||
_JobStatus: {
|
||||
"jobName": {type: 'String'},
|
||||
|
||||
@@ -47,7 +47,7 @@ export class PushWorker {
|
||||
}
|
||||
}
|
||||
|
||||
run({ body, query, pushStatus, applicationId }: any): Promise<*> {
|
||||
run({ body, query, pushStatus, applicationId, UTCOffset }: any): Promise<*> {
|
||||
const config = new Config(applicationId);
|
||||
const auth = master(config);
|
||||
const where = utils.applyDeviceTokenExists(query.where);
|
||||
@@ -56,13 +56,13 @@ export class PushWorker {
|
||||
if (results.length == 0) {
|
||||
return;
|
||||
}
|
||||
return this.sendToAdapter(body, results, pushStatus, config);
|
||||
return this.sendToAdapter(body, results, pushStatus, config, UTCOffset);
|
||||
}, err => {
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
|
||||
sendToAdapter(body: any, installations: any[], pushStatus: any, config: Config): Promise<*> {
|
||||
sendToAdapter(body: any, installations: any[], pushStatus: any, config: Config, UTCOffset: ?any): Promise<*> {
|
||||
pushStatus = pushStatusHandler(config, pushStatus.objectId);
|
||||
// Check if we have locales in the push body
|
||||
const locales = utils.getLocalesFromPush(body);
|
||||
@@ -75,7 +75,7 @@ export class PushWorker {
|
||||
const promises = Object.keys(grouppedInstallations).map((locale) => {
|
||||
const installations = grouppedInstallations[locale];
|
||||
const body = bodiesPerLocales[locale];
|
||||
return this.sendToAdapter(body, installations, pushStatus, config);
|
||||
return this.sendToAdapter(body, installations, pushStatus, config, UTCOffset);
|
||||
});
|
||||
return Promise.all(promises);
|
||||
}
|
||||
@@ -83,7 +83,7 @@ export class PushWorker {
|
||||
if (!utils.isPushIncrementing(body)) {
|
||||
logger.verbose(`Sending push to ${installations.length}`);
|
||||
return this.adapter.send(body, installations, pushStatus.objectId).then((results) => {
|
||||
return pushStatus.trackSent(results);
|
||||
return pushStatus.trackSent(results, UTCOffset).then(() => results);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ export class PushWorker {
|
||||
const payload = deepcopy(body);
|
||||
payload.data.badge = parseInt(badge);
|
||||
const installations = badgeInstallationsMap[badge];
|
||||
return this.sendToAdapter(payload, installations, pushStatus, config);
|
||||
return this.sendToAdapter(payload, installations, pushStatus, config, UTCOffset);
|
||||
});
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ export function pushStatusHandler(config, objectId = newObjectId(config.objectId
|
||||
{status: "running", updatedAt: new Date(), count });
|
||||
}
|
||||
|
||||
const trackSent = function(results, cleanupInstallations = process.env.PARSE_SERVER_CLEANUP_INVALID_INSTALLATIONS) {
|
||||
const trackSent = function(results, UTCOffset, cleanupInstallations = process.env.PARSE_SERVER_CLEANUP_INVALID_INSTALLATIONS) {
|
||||
const update = {
|
||||
updatedAt: new Date(),
|
||||
numSent: 0,
|
||||
@@ -179,6 +179,10 @@ export function pushStatusHandler(config, objectId = newObjectId(config.objectId
|
||||
const deviceType = result.device.deviceType;
|
||||
const key = result.transmitted ? `sentPerType.${deviceType}` : `failedPerType.${deviceType}`;
|
||||
memo[key] = incrementOp(memo, key);
|
||||
if (typeof UTCOffset !== 'undefined') {
|
||||
const offsetKey = result.transmitted ? `sentPerUTCOffset.${UTCOffset}` : `failedPerUTCOffset.${UTCOffset}`;
|
||||
memo[offsetKey] = incrementOp(memo, offsetKey);
|
||||
}
|
||||
if (result.transmitted) {
|
||||
memo.numSent++;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user