From 8d19edf256d0a7b89e7999e9ec808142fbd5e9a3 Mon Sep 17 00:00:00 2001 From: Ido Shamun Date: Tue, 28 May 2024 17:42:45 +0300 Subject: [PATCH 1/2] refactor: add logs to debug cio issue --- .infra/index.ts | 4 +++- src/workers/newNotificationV2Mail.ts | 18 ++++++++++++++++++ src/workers/userUpdatedCio.ts | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/.infra/index.ts b/.infra/index.ts index acb454756..85252f566 100644 --- a/.infra/index.ts +++ b/.infra/index.ts @@ -302,6 +302,7 @@ if (isAdhocEnv) { { nameSuffix: 'bg', args: ['dumb-init', 'node', 'bin/cli', 'background'], + env: [...jwtEnv], minReplicas: 3, maxReplicas: 10, limits: bgLimits, @@ -313,6 +314,7 @@ if (isAdhocEnv) { }, ports: [{ containerPort: 9464, name: 'metrics' }], servicePorts: [{ targetPort: 9464, port: 9464, name: 'metrics' }], + ...jwtVols, }, { nameSuffix: 'private', @@ -559,7 +561,7 @@ if (!isAdhocEnv) { { isAdhocEnv: isAdhocEnv, namespace: namespace, - env: [{name: "JAVA_OPTS", value: "-Xmx3840m -Xms1024m"}], + env: [{ name: 'JAVA_OPTS', value: '-Xmx3840m -Xms1024m' }], props: { path: './clickhouse-sync.yml', keys: { diff --git a/src/workers/newNotificationV2Mail.ts b/src/workers/newNotificationV2Mail.ts index 1348f73ba..f71f15c07 100644 --- a/src/workers/newNotificationV2Mail.ts +++ b/src/workers/newNotificationV2Mail.ts @@ -594,6 +594,8 @@ const formatTemplateDate = (data: T): T => { const BATCH_SIZE = 1; const QUEUE_CONCURRENCY = 100; +const IDO_ID = '28849d86070e4c099c877ab6837c61f0'; + const worker: Worker = { subscription: 'api.new-notification-mail', handler: async (message, con, logger): Promise => { @@ -610,6 +612,13 @@ const worker: Worker = { await processStreamInBatches( stream, async (batch: { userId: string }[]) => { + const debug = !!batch.find((b) => b.userId === IDO_ID); + if (debug) { + logger.info( + { notification }, + 'starting to send notification email', + ); + } const users = await con.getRepository(User).find({ select: ['id', 'username', 'email'], where: { @@ -618,6 +627,9 @@ const worker: Worker = { notificationEmail: notification.public ? true : undefined, }, }); + if (debug) { + logger.info({ users: users.map((u) => u.username) }, 'found users'); + } if (!users.length) { return; } @@ -632,6 +644,12 @@ const worker: Worker = { attachments, avatars, ); + if (debug) { + logger.info( + { templateData, userId: user.id }, + 'got template data', + ); + } if (!templateData) { return; } diff --git a/src/workers/userUpdatedCio.ts b/src/workers/userUpdatedCio.ts index 501ab808d..f8d546b02 100644 --- a/src/workers/userUpdatedCio.ts +++ b/src/workers/userUpdatedCio.ts @@ -18,7 +18,7 @@ const worker: TypedWorker<'user-updated'> = { } await identifyUser(log, cio, user); - log.info({ userId: user.id }, 'updated user profile in customerio'); + log.debug({ userId: user.id }, 'updated user profile in customerio'); }, }; From 3e8a1664a7df24f56e1b7874e70ae44accce1193 Mon Sep 17 00:00:00 2001 From: Ido Shamun Date: Tue, 28 May 2024 17:57:13 +0300 Subject: [PATCH 2/2] fix: send only required fields for squad_new_comment --- src/workers/newNotificationV2Mail.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/workers/newNotificationV2Mail.ts b/src/workers/newNotificationV2Mail.ts index f71f15c07..e6ad6b9e5 100644 --- a/src/workers/newNotificationV2Mail.ts +++ b/src/workers/newNotificationV2Mail.ts @@ -357,9 +357,8 @@ const notificationToTemplateData: Record = { if (!post || !post?.sharedPostId || !post?.authorId) { return; } - const [sharedPost, author, source] = await Promise.all([ + const [sharedPost, source] = await Promise.all([ con.getRepository(Post).findOneBy({ id: post.sharedPostId }), - post.author, post.source, ]); return { @@ -368,16 +367,12 @@ const notificationToTemplateData: Record = { squad_name: source.name, squad_image: source.image, post_title: truncatePostToTweet(sharedPost), - post_image: (sharedPost as ArticlePost).image || pickImageUrl(post), new_comment: notification.description, post_link: addNotificationEmailUtm( notification.targetUrl, notification.type, ), commenter_reputation: commenter.reputation, - user_name: author.name, - user_reputation: author.reputation, - user_image: author.image, commentary: truncatePostToTweet(post), }; },