Skip to content

Commit c4b3262

Browse files
authored
Merge pull request #7147 from Countly/SER-2779-push-cancellation-on-cohort-exit-doesnt-work
[SER-2779] Message cancellation doesn't work on cohort exit
2 parents 3bba32b + b779165 commit c4b3262

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

plugins/push/api/api-auto.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,8 @@ module.exports.autoOnCohort = function(entry, cohort, uids) {
4848
// adding messages to queue
4949
if (trigger) {
5050
logCohorts.d('processing %s %s', typ, msg._id);
51-
audience.getApp().then(() => {
52-
audience.push(trigger).setUIDs(uids).setStart(new Date()).run().then(result => {
53-
logCohorts.d('processing %s %s, result: %j', typ, msg._id, result);
54-
if (result.total) {
55-
return msg.update({$inc: {'result.total': result.total}}, () => {
56-
msg.result.total += result.total;
57-
});
58-
}
59-
}).then(() => {
51+
audience.getApp().then(async() => {
52+
audience.push(trigger).setUIDs(uids).setStart(new Date()).run().then(() => {
6053
logCohorts.d('done processing %s %s', typ, msg._id);
6154
}).catch(error => {
6255
logCohorts.e('Error while pushing users to cohorted message queue %s %s', typ, msg._id, error);

plugins/push/api/send/audience.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -756,16 +756,22 @@ class Popper extends PusherPopper {
756756
*/
757757
async run() {
758758
this.audience.log.i('popping %d uids from %s', this.uids.length, this.audience.message._id);
759+
return this.clear(this.uids);
759760
}
760761

761762
/**
762-
* Remove all message pushes
763-
*
763+
* Remove all message pushes or those for specified uids
764+
*
765+
* @param {string[]} uids optional array of uids to remove pushes for
764766
* @returns {number} number of records removed
765767
*/
766-
async clear() {
768+
async clear(uids) {
767769
let deleted = await Promise.all(this.audience.platformsWithVirtuals().map(async p => {
768-
let res = await common.db.collection('push').deleteMany({m: this.audience.message._id, p});
770+
const query = {m: this.audience.message._id, p};
771+
if (uids) {
772+
query.u = { $in: uids };
773+
}
774+
let res = await common.db.collection('push').deleteMany(query);
769775
return {p, deleted: res.deletedCount};
770776
}));
771777
let update;
@@ -775,7 +781,9 @@ class Popper extends PusherPopper {
775781
}
776782
update.$inc['result.processed'] = (update.$inc['result.processed'] || 0) + obj.deleted;
777783
update.$inc['result.errored'] = (update.$inc['result.errored'] || 0) + obj.deleted;
778-
update.$inc[`result.errors.${obj.p}.cancelled`] = (update.$inc[`result.errors.${obj.p}.cancelled`] || 0) + obj.deleted;
784+
update.$inc[`result.errors.cancelled`] = (update.$inc[`result.errors.cancelled`] || 0) + obj.deleted;
785+
update.$inc[`result.subs.${obj.p}.errors.cancelled`] = (update.$inc[`result.subs.${obj.p}.errors.cancelled`] || 0) + obj.deleted;
786+
update.$inc[`result.subs.${obj.p}.errored`] = (update.$inc[`result.subs.${obj.p}.errored`] || 0) + obj.deleted;
779787
}
780788
if (update) {
781789
await this.audience.message.update(update, () => {

0 commit comments

Comments
 (0)