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:
Florent Vilmart
2017-09-13 17:28:20 -04:00
committed by GitHub
parent be2760f9dd
commit d598d73f36
4 changed files with 160 additions and 22 deletions

View File

@@ -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);
}