Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions plugins/push/api/api-auto.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,8 @@ module.exports.autoOnCohort = function(entry, cohort, uids) {
// adding messages to queue
if (trigger) {
logCohorts.d('processing %s %s', typ, msg._id);
audience.getApp().then(() => {
audience.push(trigger).setUIDs(uids).setStart(new Date()).run().then(result => {
logCohorts.d('processing %s %s, result: %j', typ, msg._id, result);
if (result.total) {
return msg.update({$inc: {'result.total': result.total}}, () => {
msg.result.total += result.total;
});
}
}).then(() => {
audience.getApp().then(async() => {
audience.push(trigger).setUIDs(uids).setStart(new Date()).run().then(() => {
logCohorts.d('done processing %s %s', typ, msg._id);
}).catch(error => {
logCohorts.e('Error while pushing users to cohorted message queue %s %s', typ, msg._id, error);
Expand Down
18 changes: 13 additions & 5 deletions plugins/push/api/send/audience.js
Original file line number Diff line number Diff line change
Expand Up @@ -756,16 +756,22 @@ class Popper extends PusherPopper {
*/
async run() {
this.audience.log.i('popping %d uids from %s', this.uids.length, this.audience.message._id);
return this.clear(this.uids);
}

/**
* Remove all message pushes
*
* Remove all message pushes or those for specified uids
*
* @param {string[]} uids optional array of uids to remove pushes for
* @returns {number} number of records removed
*/
async clear() {
async clear(uids) {
let deleted = await Promise.all(this.audience.platformsWithVirtuals().map(async p => {
let res = await common.db.collection('push').deleteMany({m: this.audience.message._id, p});
const query = {m: this.audience.message._id, p};
if (uids) {
query.u = { $in: uids };
}
let res = await common.db.collection('push').deleteMany(query);
return {p, deleted: res.deletedCount};
}));
let update;
Expand All @@ -775,7 +781,9 @@ class Popper extends PusherPopper {
}
update.$inc['result.processed'] = (update.$inc['result.processed'] || 0) + obj.deleted;
update.$inc['result.errored'] = (update.$inc['result.errored'] || 0) + obj.deleted;
update.$inc[`result.errors.${obj.p}.cancelled`] = (update.$inc[`result.errors.${obj.p}.cancelled`] || 0) + obj.deleted;
update.$inc[`result.errors.cancelled`] = (update.$inc[`result.errors.cancelled`] || 0) + obj.deleted;
update.$inc[`result.subs.${obj.p}.errors.cancelled`] = (update.$inc[`result.subs.${obj.p}.errors.cancelled`] || 0) + obj.deleted;
update.$inc[`result.subs.${obj.p}.errored`] = (update.$inc[`result.subs.${obj.p}.errored`] || 0) + obj.deleted;
}
if (update) {
await this.audience.message.update(update, () => {
Expand Down
Loading