Skip to content

Commit c574db5

Browse files
github-actions[bot]slaveeksDobruniae11sy
authored
Update prod (#463)
* chore: added try-catch for sending report (#457) * chore: added try-catch for sending report * added res log * chore(license): adopt BSL 1.1 (#460) * chore: update license to BUSL-1.1 in package.json and README.md * chore: update licensed work reference in LICENSE file * imp(): get rid of duplicated releases (#462) * imp(): get rid of duplicated releases * chore(): eslint fix * fix(grouper): skip notifications for muted errors (#459) * feat(grouper): add event ignored check before notifying worker * Implemented a new method to check if an event is marked as ignored. * Updated the notifier task addition to only proceed if the event is not ignored. * Removed the isEventIgnored method as its functionality is now integrated directly into the task addition logic. * Removed unnecessary line break * update @hawk.so/types dependency to version 0.1.35 * add tests for event marks handling in NotifierWorker * fix --------- Co-authored-by: Vyacheslav Chernyshev <81693471+slaveeks@users.noreply.github.com> Co-authored-by: Dobrunia Kostrigin <48620984+Dobrunia@users.noreply.github.com> Co-authored-by: e11sy <130844513+e11sy@users.noreply.github.com>
1 parent d410a4b commit c574db5

4 files changed

Lines changed: 97 additions & 15 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
},
5050
"dependencies": {
5151
"@hawk.so/nodejs": "^3.1.1",
52-
"@hawk.so/types": "^0.1.32",
52+
"@hawk.so/types": "^0.1.35",
5353
"@types/amqplib": "^0.8.2",
5454
"@types/jest": "^29.2.3",
5555
"@types/mongodb": "^3.5.15",

workers/grouper/src/index.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -223,20 +223,30 @@ export default class GrouperWorker extends Worker {
223223
/**
224224
* Store events counter by days
225225
*/
226-
await this.saveDailyEvents(task.projectId, uniqueEventHash, task.timestamp, repetitionId, incrementDailyAffectedUsers);
226+
await this.saveDailyEvents(
227+
task.projectId,
228+
uniqueEventHash,
229+
task.timestamp,
230+
repetitionId,
231+
incrementDailyAffectedUsers
232+
);
227233

228234
/**
229-
* Add task for NotifierWorker
235+
* Add task for NotifierWorker only if event is not ignored
230236
*/
231237
if (process.env.IS_NOTIFIER_WORKER_ENABLED) {
232-
await this.addTask(WorkerNames.NOTIFIER, {
233-
projectId: task.projectId,
234-
event: {
235-
title: task.payload.title,
236-
groupHash: uniqueEventHash,
237-
isNew: isFirstOccurrence,
238-
},
239-
});
238+
const isIgnored = isFirstOccurrence ? false : !!existedEvent?.marks?.ignored;
239+
240+
if (!isIgnored) {
241+
await this.addTask(WorkerNames.NOTIFIER, {
242+
projectId: task.projectId,
243+
event: {
244+
title: task.payload.title,
245+
groupHash: uniqueEventHash,
246+
isNew: isFirstOccurrence,
247+
},
248+
});
249+
}
240250
}
241251
}
242252

workers/grouper/tests/index.test.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,78 @@ describe('GrouperWorker', () => {
589589
});
590590
});
591591

592+
describe('Event marks handling', () => {
593+
describe('Ignored events', () => {
594+
it('should not add task for NotifierWorker when event is marked as ignored', async () => {
595+
const mockAddTask = jest
596+
.spyOn(worker as any, 'addTask')
597+
.mockImplementation(() => Promise.resolve());
598+
599+
// Create an event first
600+
const firstTask = generateTask({ title: 'Test ignored event' });
601+
await worker.handle(firstTask);
602+
603+
// Mark the event as ignored by updating it in database
604+
const eventHash = await (worker as any).getUniqueEventHash(firstTask);
605+
await eventsCollection.updateOne(
606+
{ groupHash: eventHash },
607+
{ $set: { marks: { ignored: true } } }
608+
);
609+
610+
// Handle the same event again (repetition)
611+
const secondTask = generateTask({ title: 'Test ignored event' });
612+
await worker.handle(secondTask);
613+
614+
// Verify that addTask was called only once (for the first occurrence)
615+
expect(mockAddTask).toHaveBeenCalledTimes(1);
616+
617+
mockAddTask.mockRestore();
618+
});
619+
620+
it('should add task for NotifierWorker when event is not marked as ignored', async () => {
621+
const mockAddTask = jest
622+
.spyOn(worker as any, 'addTask')
623+
.mockImplementation(() => Promise.resolve());
624+
625+
// Create an event first
626+
const firstTask = generateTask({ title: 'Test non-ignored event' });
627+
await worker.handle(firstTask);
628+
629+
// Handle the same event again (repetition) - without marking as ignored
630+
const secondTask = generateTask({ title: 'Test non-ignored event' });
631+
await worker.handle(secondTask);
632+
633+
// Verify that addTask was called twice (for both occurrences)
634+
expect(mockAddTask).toHaveBeenCalledTimes(2);
635+
636+
mockAddTask.mockRestore();
637+
});
638+
639+
it('should add task for NotifierWorker for first occurrence even if marks field is undefined', async () => {
640+
const mockAddTask = jest
641+
.spyOn(worker as any, 'addTask')
642+
.mockImplementation(() => Promise.resolve());
643+
644+
// Create a new event (first occurrence)
645+
const task = generateTask({ title: 'Test new event without marks' });
646+
await worker.handle(task);
647+
648+
// Verify that addTask was called for the first occurrence
649+
expect(mockAddTask).toHaveBeenCalledTimes(1);
650+
expect(mockAddTask).toHaveBeenCalledWith('notifier', {
651+
projectId: task.projectId,
652+
event: {
653+
title: task.payload.title,
654+
groupHash: expect.any(String),
655+
isNew: true,
656+
},
657+
});
658+
659+
mockAddTask.mockRestore();
660+
});
661+
});
662+
});
663+
592664
afterAll(async () => {
593665
await redisClient.quit();
594666
await worker.finish();

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,10 +428,10 @@
428428
dependencies:
429429
"@types/mongodb" "^3.5.34"
430430

431-
"@hawk.so/types@^0.1.32":
432-
version "0.1.32"
433-
resolved "https://registry.yarnpkg.com/@hawk.so/types/-/types-0.1.32.tgz#5eb662e91da922e1cbab7af0cf03bfa567ee98df"
434-
integrity sha512-7gdx/fq31iLxmc0hZKs+wPYqtRT4rLvTi9p4am2My9SQ4t/l8if5QEfxh6G4WABKOmhiZLchivFA9Oj+Nn5EcQ==
431+
"@hawk.so/types@^0.1.35":
432+
version "0.1.35"
433+
resolved "https://registry.yarnpkg.com/@hawk.so/types/-/types-0.1.35.tgz#6afd416dced1cc3282d721ca5621bf452b27aea1"
434+
integrity sha512-uMTAeu6DlRlk+oputJBjTlrm1GzOkIwlMfGhpdOp3sRWe/YPGD6nMYlb9MZoVN6Yee7RIpYD7It+DPeUPAyIFw==
435435
dependencies:
436436
"@types/mongodb" "^3.5.34"
437437

0 commit comments

Comments
 (0)