Skip to content

Commit

Permalink
Merge pull request #4647 from Countly/hotfix/psh
Browse files Browse the repository at this point in the history
Hotfix/psh
  • Loading branch information
kanwarujjaval authored Oct 25, 2023
2 parents fbbb74a + 92db21f commit 09fd9c1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 27 deletions.
2 changes: 1 addition & 1 deletion api/parts/data/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ class StreamedCollection {
let [col, last] = await createCollection(this.db, this.name, 1e7);

this.col = col;
this.stream = col.find({_id: {$gt: last}}, {tailable: true, awaitData: true, noCursorTimeout: true, numberOfRetries: -1}).stream();
this.stream = col.find({_id: {$gt: last}}, {tailable: true, awaitData: true, numberOfRetries: -1}).stream();

this.stream.on('data', doc => {
if (this.inserts.indexOf(doc._id.toString()) !== -1) {
Expand Down
1 change: 1 addition & 0 deletions plugins/push/api/send/data/trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,7 @@ class MultiTrigger extends ReschedulingTrigger {
*/
set dates(dates) {
if (Array.isArray(dates) && !dates.filter(n => !(n instanceof Date)).length) {
dates.sort();
this._data.dates = dates;
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1028,10 +1028,10 @@
},
calculateDeliveryDates: function(prev, last) {
var nextDeliveryDates = [];
if (prev) {
if (prev && prev > Date.now()) {
nextDeliveryDates.push(this.formatDateTime(prev, 'DD MMMM YYYY'));
}
if (last) {
if (last && last > Date.now() && last !== prev) {
nextDeliveryDates.push(this.formatDateTime(last, 'DD MMMM YYYY'));
}
return nextDeliveryDates.join(', ');
Expand Down
8 changes: 2 additions & 6 deletions plugins/push/frontend/public/javascripts/countly.views.js
Original file line number Diff line number Diff line change
Expand Up @@ -1583,9 +1583,7 @@
if (!this.canUserUpdate) {
return false;
}
return status === this.StatusEnum.CREATED
|| status === this.StatusEnum.SENT
|| status === this.StatusEnum.STOPPED
return status === this.StatusEnum.STOPPED
|| status === this.StatusEnum.FAILED;
},
shouldShowStopUserCommand: function(status) {
Expand Down Expand Up @@ -2036,9 +2034,7 @@
if (!this.canUserUpdate) {
return false;
}
return status === this.StatusEnum.CREATED
|| status === this.StatusEnum.SENT
|| status === this.StatusEnum.STOPPED
return status === this.StatusEnum.STOPPED
|| status === this.StatusEnum.FAILED;
},
shouldShowStopUserCommand: function(status) {
Expand Down
37 changes: 19 additions & 18 deletions plugins/push/tests/tests-recurring-trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ describe('PUSH RECURRING', () => {
should.equal(start.getTime() - SCHEDULE_AHEAD, trigger.scheduleDate(trigger.nextReference(), now).getTime());
should.equal(start.getTime(), trigger.nextReference(new Date(start.getTime() - 1)).getTime());
should.equal(start.getTime() - SCHEDULE_AHEAD, trigger.scheduleDate(trigger.nextReference(new Date(start.getTime() - 1)), now).getTime());
should.equal(later.getTime() - SCHEDULE_AHEAD, trigger.scheduleDate(trigger.nextReference(new Date(start.getTime() - 1)), nowSkip).getTime());
should.equal(start.getTime() - SCHEDULE_AHEAD, trigger.scheduleDate(trigger.nextReference(new Date(start.getTime() - 1)), nowSkip).getTime());
should.equal(later.getTime() - SCHEDULE_AHEAD, trigger.scheduleDate(trigger.nextReference(new Date(start.getTime() + 1)), nowSkip).getTime());
should.equal(later.getTime(), trigger.nextReference(start).getTime());
should.equal(later.getTime() - SCHEDULE_AHEAD, trigger.scheduleDate(trigger.nextReference(start), now).getTime());
should.equal(later.getTime(), trigger.nextReference(new Date(start.getTime() + 20)).getTime());
should.equal(later.getTime() - SCHEDULE_AHEAD, trigger.scheduleDate(trigger.nextReference(new Date(start.getTime() + 20)), now).getTime());
should.equal(null, trigger.scheduleDate(trigger.nextReference(new Date(start.getTime() + 20)), nowBad));
should.equal(null, trigger.scheduleDate(trigger.nextReference(nowBad)));
should.equal(null, trigger.nextReference(later));
should.equal(null, trigger.scheduleDate(trigger.nextReference(later), now));
should.equal(null, trigger.nextReference(new Date(later.getTime() + 5 * 60000)));
Expand Down Expand Up @@ -67,16 +68,16 @@ describe('PUSH RECURRING', () => {
}),
mapper = new MultiRecurringMapper({_id: 'appid', timezone: 'Europe/Moscow'}, new Message({triggers: [trigger.json]}), trigger, 'i', 'p');

should.equal(first.getTime() + sctz * 60000, trigger.nextReference().getTime());
should.equal(first.getTime() + sctz * 60000 - EASTMOST_TIMEZONE - SCHEDULE_AHEAD, trigger.scheduleDate(trigger.nextReference(), now).getTime());
should.equal(first.getTime() + sctz * 60000, trigger.nextReference(start).getTime());
should.equal(first.getTime() + sctz * 60000 - EASTMOST_TIMEZONE - SCHEDULE_AHEAD, trigger.scheduleDate(trigger.nextReference(start), now).getTime());
should.equal(second.getTime() + sctz * 60000, trigger.nextReference(new Date(first.getTime() + 20)).getTime());
should.equal(second.getTime() + sctz * 60000 - EASTMOST_TIMEZONE - SCHEDULE_AHEAD, trigger.scheduleDate(trigger.nextReference(new Date(first.getTime() + 20)), now).getTime());
should.equal(third.getTime() + sctz * 60000, trigger.nextReference(new Date(second.getTime() + 20)).getTime());
should.equal(third.getTime() + sctz * 60000 - EASTMOST_TIMEZONE - SCHEDULE_AHEAD, trigger.scheduleDate(trigger.nextReference(new Date(second.getTime() + 20)), now).getTime());
should.equal(null, trigger.nextReference(third));
should.equal(null, trigger.scheduleDate(trigger.nextReference(third), now));
should.equal(first.getTime() - sctz * 60000, trigger.nextReference().getTime());
should.equal(first.getTime() - sctz * 60000 - EASTMOST_TIMEZONE - SCHEDULE_AHEAD, trigger.scheduleDate(trigger.nextReference(), now).getTime());
should.equal(first.getTime() - sctz * 60000, trigger.nextReference(start).getTime());
should.equal(first.getTime() - sctz * 60000 - EASTMOST_TIMEZONE - SCHEDULE_AHEAD, trigger.scheduleDate(trigger.nextReference(start), now).getTime());
should.equal(second.getTime() - sctz * 60000, trigger.nextReference(new Date(first.getTime() - sctz * 60000 + 20)).getTime());
should.equal(second.getTime() - sctz * 60000 - EASTMOST_TIMEZONE - SCHEDULE_AHEAD, trigger.scheduleDate(trigger.nextReference(new Date(first.getTime() - sctz * 60000 + 20)), now).getTime());
should.equal(third.getTime() - sctz * 60000, trigger.nextReference(new Date(second.getTime() - sctz * 60000 + 20)).getTime());
should.equal(third.getTime() - sctz * 60000 - EASTMOST_TIMEZONE - SCHEDULE_AHEAD, trigger.scheduleDate(trigger.nextReference(new Date(second.getTime() - sctz * 60000 + 20)), now).getTime());
should.equal(null, trigger.nextReference(third.getTime() - sctz * 60000));
should.equal(null, trigger.scheduleDate(trigger.nextReference(third.getTime() - sctz * 60000), now));
should.equal(null, trigger.nextReference(new Date(third.getTime() + 5 * 60000)));
should.equal(null, trigger.scheduleDate(trigger.nextReference(new Date(third.getTime() + 5 * 60000)), now));

Expand Down Expand Up @@ -107,12 +108,12 @@ describe('PUSH RECURRING', () => {
second = trigger.nextReference(first),
third = trigger.nextReference(second);

should.equal(startZero.getTime() + time + Time.DAY + 0 * every * 24 * 60 * 60000, first.getTime());
should.equal(startZero.getTime() + time + Time.DAY + 0 * every * 24 * 60 * 60000 - EASTMOST_TIMEZONE - SCHEDULE_AHEAD, trigger.scheduleDate(first, now).getTime());
should.equal(startZero.getTime() + time + Time.DAY + 1 * every * 24 * 60 * 60000, second.getTime());
should.equal(startZero.getTime() + time + Time.DAY + 1 * every * 24 * 60 * 60000 - EASTMOST_TIMEZONE - SCHEDULE_AHEAD, trigger.scheduleDate(second, now).getTime());
should.equal(startZero.getTime() + time + Time.DAY + 2 * every * 24 * 60 * 60000, third.getTime());
should.equal(startZero.getTime() + time + Time.DAY + 2 * every * 24 * 60 * 60000 - EASTMOST_TIMEZONE - SCHEDULE_AHEAD, trigger.scheduleDate(third, now).getTime());
should.equal(startZero.getTime() + time + 0 * every * 24 * 60 * 60000, first.getTime());
should.equal(startZero.getTime() + time + 0 * every * 24 * 60 * 60000 - EASTMOST_TIMEZONE - SCHEDULE_AHEAD, trigger.scheduleDate(first, now).getTime());
should.equal(startZero.getTime() + time + 1 * every * 24 * 60 * 60000, second.getTime());
should.equal(startZero.getTime() + time + 1 * every * 24 * 60 * 60000 - EASTMOST_TIMEZONE - SCHEDULE_AHEAD, trigger.scheduleDate(second, now).getTime());
should.equal(startZero.getTime() + time + 2 * every * 24 * 60 * 60000, third.getTime());
should.equal(startZero.getTime() + time + 2 * every * 24 * 60 * 60000 - EASTMOST_TIMEZONE - SCHEDULE_AHEAD, trigger.scheduleDate(third, now).getTime());

let mapped = users.map(u => mapper.map(u, start));
should.equal(mapped[0]._id.getTimestamp().getTime(), start.getTime());
Expand Down

0 comments on commit 09fd9c1

Please sign in to comment.