Improves report for Push error in logs and _PushStatus
This commit is contained in:
@@ -317,6 +317,45 @@ describe('PushController', () => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should properly report failures in _PushStatus', (done) => {
|
||||||
|
var pushAdapter = {
|
||||||
|
send: function(body, installations) {
|
||||||
|
return installations.map((installation) => {
|
||||||
|
return Promise.resolve({
|
||||||
|
deviceType: installation.deviceType
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
getValidPushTypes: function() {
|
||||||
|
return ["ios"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let where = { 'channels': {
|
||||||
|
'$ins': ['Giants', 'Mets']
|
||||||
|
}};
|
||||||
|
var payload = {data: {
|
||||||
|
alert: "Hello World!",
|
||||||
|
badge: 1,
|
||||||
|
}}
|
||||||
|
var config = new Config(Parse.applicationId);
|
||||||
|
var auth = {
|
||||||
|
isMaster: true
|
||||||
|
}
|
||||||
|
var pushController = new PushController(pushAdapter, Parse.applicationId);
|
||||||
|
pushController.sendPush(payload, where, config, auth).then(() => {
|
||||||
|
fail('should not succeed');
|
||||||
|
done();
|
||||||
|
}).catch(() => {
|
||||||
|
let query = new Parse.Query('_PushStatus');
|
||||||
|
query.find({useMasterKey: true}).then((results) => {
|
||||||
|
expect(results.length).toBe(1);
|
||||||
|
let pushStatus = results[0];
|
||||||
|
expect(pushStatus.get('status')).toBe('failed');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
it('should support full RESTQuery for increment', (done) => {
|
it('should support full RESTQuery for increment', (done) => {
|
||||||
var payload = {data: {
|
var payload = {data: {
|
||||||
alert: "Hello World!",
|
alert: "Hello World!",
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ export class PushController extends AdaptableController {
|
|||||||
let badgeUpdate = () => {
|
let badgeUpdate = () => {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (body.data && body.data.badge) {
|
if (body.data && body.data.badge) {
|
||||||
let badge = body.data.badge;
|
let badge = body.data.badge;
|
||||||
let op = {};
|
let op = {};
|
||||||
@@ -89,10 +88,16 @@ export class PushController extends AdaptableController {
|
|||||||
}).then(() => {
|
}).then(() => {
|
||||||
return rest.find(config, auth, '_Installation', where);
|
return rest.find(config, auth, '_Installation', where);
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
pushStatus.setRunning();
|
if (!response.results) {
|
||||||
|
return Promise.reject({error: 'PushController: no results in query'})
|
||||||
|
}
|
||||||
|
pushStatus.setRunning(response.results);
|
||||||
return this.sendToAdapter(body, response.results, pushStatus, config);
|
return this.sendToAdapter(body, response.results, pushStatus, config);
|
||||||
}).then((results) => {
|
}).then((results) => {
|
||||||
return pushStatus.complete(results);
|
return pushStatus.complete(results);
|
||||||
|
}).catch((err) => {
|
||||||
|
pushStatus.fail(err);
|
||||||
|
return Promise.reject(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { md5Hash, newObjectId } from './cryptoUtils';
|
import { md5Hash, newObjectId } from './cryptoUtils';
|
||||||
|
import { logger } from './logger';
|
||||||
|
|
||||||
export function flatten(array) {
|
export function flatten(array) {
|
||||||
return array.reduce((memo, element) => {
|
return array.reduce((memo, element) => {
|
||||||
@@ -20,8 +21,9 @@ export default function pushStatusHandler(config) {
|
|||||||
return config.database.adaptiveCollection('_PushStatus');
|
return config.database.adaptiveCollection('_PushStatus');
|
||||||
}
|
}
|
||||||
|
|
||||||
let setInitial = function(body, where, options = {source: 'rest'}) {
|
let setInitial = function(body = {}, where, options = {source: 'rest'}) {
|
||||||
let now = new Date();
|
let now = new Date();
|
||||||
|
let data = body.data || {};
|
||||||
let object = {
|
let object = {
|
||||||
objectId: newObjectId(),
|
objectId: newObjectId(),
|
||||||
pushTime: now.toISOString(),
|
pushTime: now.toISOString(),
|
||||||
@@ -33,7 +35,7 @@ export default function pushStatusHandler(config) {
|
|||||||
expiry: body.expiration_time,
|
expiry: body.expiration_time,
|
||||||
status: "pending",
|
status: "pending",
|
||||||
numSent: 0,
|
numSent: 0,
|
||||||
pushHash: md5Hash(JSON.stringify(body.data)),
|
pushHash: md5Hash(JSON.stringify(data)),
|
||||||
// lockdown!
|
// lockdown!
|
||||||
_wperm: [],
|
_wperm: [],
|
||||||
_rperm: []
|
_rperm: []
|
||||||
@@ -49,7 +51,8 @@ export default function pushStatusHandler(config) {
|
|||||||
return initialPromise;
|
return initialPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
let setRunning = function() {
|
let setRunning = function(installations) {
|
||||||
|
logger.verbose('sending push to %d installations', installations.length);
|
||||||
return initialPromise.then(() => {
|
return initialPromise.then(() => {
|
||||||
return collection();
|
return collection();
|
||||||
}).then((collection) => {
|
}).then((collection) => {
|
||||||
@@ -86,7 +89,7 @@ export default function pushStatusHandler(config) {
|
|||||||
return memo;
|
return memo;
|
||||||
}, update);
|
}, update);
|
||||||
}
|
}
|
||||||
|
logger.verbose('sent push! %d success, %d failures', update.numSent, update.numFailed);
|
||||||
return initialPromise.then(() => {
|
return initialPromise.then(() => {
|
||||||
return collection();
|
return collection();
|
||||||
}).then((collection) => {
|
}).then((collection) => {
|
||||||
@@ -94,9 +97,23 @@ export default function pushStatusHandler(config) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let fail = function(err) {
|
||||||
|
let update = {
|
||||||
|
errorMessage: JSON.stringify(err),
|
||||||
|
status: 'failed'
|
||||||
|
}
|
||||||
|
logger.error('error while sending push', err);
|
||||||
|
return initialPromise.then(() => {
|
||||||
|
return collection();
|
||||||
|
}).then((collection) => {
|
||||||
|
return collection.updateOne({objectId: pushStatus.objectId}, {$set: update});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return Object.freeze({
|
return Object.freeze({
|
||||||
setInitial,
|
setInitial,
|
||||||
setRunning,
|
setRunning,
|
||||||
complete
|
complete,
|
||||||
|
fail
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user