diff --git a/.github/assets/Hawk.png b/.github/assets/Hawk.png new file mode 100644 index 00000000..11f183dc Binary files /dev/null and b/.github/assets/Hawk.png differ diff --git a/workers/email/src/templates/emails/event/html.twig b/workers/email/src/templates/emails/event/html.twig index 64b35bba..35c7c503 100644 --- a/workers/email/src/templates/emails/event/html.twig +++ b/workers/email/src/templates/emails/event/html.twig @@ -58,7 +58,7 @@ {% endblock %} {% block unsubscribeLink %} - {{ host ~ '/unsubscribe/' ~ project._id }} + {{ host ~ '/unsubscribe/' ~ project._id ~ '/' ~ notificationRuleId }} {% endblock %} {% block unsubscribeText %} diff --git a/workers/email/tests/provider.test.ts b/workers/email/tests/provider.test.ts index 1a19314f..89f39f40 100644 --- a/workers/email/tests/provider.test.ts +++ b/workers/email/tests/provider.test.ts @@ -81,6 +81,7 @@ describe('EmailProvider', () => { period: 60, host: process.env.GARAGE_URL!, hostOfStatic: process.env.API_STATIC_URL!, + notificationRuleId: '5d206f7f9aaf7c0071d64596', project: { _id: new ObjectId('5d206f7f9aaf7c0071d64596'), token: 'project-token', @@ -131,6 +132,7 @@ describe('EmailProvider', () => { }], host: process.env.GARAGE_URL!, hostOfStatic: process.env.API_STATIC_URL!, + notificationRuleId: '5d206f7f9aaf7c0071d64596', project: { _id: new ObjectId('5d206f7f9aaf7c0071d64596'), token: 'project-token', diff --git a/workers/notifier/README.md b/workers/notifier/README.md index abb6486d..707d5289 100644 --- a/workers/notifier/README.md +++ b/workers/notifier/README.md @@ -2,6 +2,11 @@ Handles new events from Grouper Worker, holds it and sends to sender worlers +This repository is a part of the Hawk ecosystemm. You can register [here](https://garage.hawk.so/login) + +![alt text](../../.github/assets/Hawk.png) + + ## How to run 1. Make sure you are in Workers root directory @@ -12,21 +17,12 @@ Handles new events from Grouper Worker, holds it and sends to sender worlers ## Events handling scheme ``` -1) On task received -> receive task -> get project notification rules -> filter rules - -> check channel timer - a) if timer doesn't exist - -> send tasks to sender workers - -> set timeout for minPeriod - b) if timer exists - -> push event to channel's buffer - -2) On timeout - -> get events from channel's buffer - -> flush channel's buffer - -> send tasks to sender workers + -> update eventsCount in redis + -> get updated eventCount + -> send notification if eventCount == treshold ``` ### Event example diff --git a/workers/sender/src/index.ts b/workers/sender/src/index.ts index fef4be5d..a92c9d19 100644 --- a/workers/sender/src/index.ts +++ b/workers/sender/src/index.ts @@ -196,6 +196,7 @@ export default abstract class SenderWorker extends Worker { project, events: eventsData, period: channel.minPeriod, + notificationRuleId: rule._id, }, } as EventNotification | SeveralEventsNotification); } diff --git a/workers/sender/types/template-variables/event.ts b/workers/sender/types/template-variables/event.ts index 51735fd2..701444ec 100644 --- a/workers/sender/types/template-variables/event.ts +++ b/workers/sender/types/template-variables/event.ts @@ -45,6 +45,12 @@ export interface EventsTemplateVariables extends CommonTemplateVariables { * Minimal pause between second notification, in seconds */ period: number; + + /** + * Id of notification rule to unsubscribe. + * Required for email notifications – to form unsubscribe link. + */ + notificationRuleId?: string; } /**