novuhq / novu

Open-Source Notification Platform. Embeddable Notification Center, E-mail, Push and Slack Integrations.
https://novu.co
Other
35.37k stars 3.92k forks source link

πŸ› Bug Report: email step in queued when generating email attachment for 6 seconds #6834

Open yunluo1024 opened 1 week ago

yunluo1024 commented 1 week ago

πŸ“œ Description

using sendgrid provider to send email with attachments, when rendering a large attachment for around 6 seconds, the email can't be sent and stuck.

πŸ‘Ÿ Reproduction steps

In sendgrid provider, when rending a large attachment, the time spent for rendering is around 6 seconds; Novu can't send the email and stuck in email step.

export const myWorkflow = workflow(
 'WorkflowName', 
  async ({ step, payload, subscriber }) => {
    await step.email(
      'send-email',
      async () => {
        const content = ListingOrderQcAcceptedEmailSeller(
          payload.emailData.content,
        );

        return {
          subject: payload.emailData.subject,
          body: render(content),
        };
      },
      {
        providers: {
          sendgrid: async () => {

            console.time('process');
            const pdfContent = await convertHtml2Pdf(
              render(
                TaxInvoiceProducePlusFreight(
                  payload.emailData.attachmentList[0].content,
                ),
              ),
            );
            console.timeLog('process');
            console.timeEnd('process');
            const attachments = [];
            attachments.push(
              getAttachment({
                fileName: payload.emailData.attachmentList[0].fileName,
                content: pdfContent,
              }),
            );

            // @ts-ignore
            return {
              attachments,
            };
          },
        },
      },
    ),
  },
  {
    payloadSchema,
  },
);

πŸ‘ Expected behavior

It should send email with attachment.

πŸ‘Ž Actual Behavior with Screenshots

stuck in email sending. Screenshot 2024-11-04 at 11 01 38β€―AM

Novu version

Novu SAAS

npm version

No response

node version

No response

πŸ“ƒ Provide any additional context for the Bug.

it actually did not send the email with attachments.

πŸ‘€ Have you spent some time to check if this bug has been raised before?

🏒 Have you read the Contributing Guidelines?

Are you willing to submit PR?

None

linear[bot] commented 1 week ago

NV-4571 πŸ› Bug Report: email step in queued when generating email attachment for 6 seconds

kasyap1234 commented 1 week ago

@yunluo1024 did you try to render the attachment asynchronously ? Offload the attachment generation to a separate, asynchronous process. You can save the generated attachment to a storage location (like S3) and then retrieve it when it is ready. I feel in this way , you wont face this issue , because rendering is taking time ,so why not offload it .