diff --git a/packages/lib/server-only/document/complete-document-with-token.ts b/packages/lib/server-only/document/complete-document-with-token.ts index 8e3b56002..5e9f56a9a 100644 --- a/packages/lib/server-only/document/complete-document-with-token.ts +++ b/packages/lib/server-only/document/complete-document-with-token.ts @@ -8,9 +8,9 @@ import { DocumentStatus, SigningStatus } from '@documenso/prisma/client'; import { WebhookTriggerEvents } from '@documenso/prisma/client'; import type { TRecipientActionAuth } from '../../types/document-auth'; +import { queueJob } from '../queue/job'; import { triggerWebhook } from '../webhooks/trigger/trigger-webhook'; import { sealDocument } from './seal-document'; -import { sendPendingEmail } from './send-pending-email'; export type CompleteDocumentWithTokenOptions = { token: string; @@ -134,7 +134,13 @@ export const completeDocumentWithToken = async ({ }); if (pendingRecipients > 0) { - await sendPendingEmail({ documentId, recipientId: recipient.id }); + await queueJob({ + job: 'send-pending-email', + args: { + documentId: document.id, + recipientId: recipient.id, + }, + }); } const documents = await prisma.document.updateMany({ diff --git a/packages/lib/server-only/queue/job.ts b/packages/lib/server-only/queue/job.ts index 39c58e374..5d8704bba 100644 --- a/packages/lib/server-only/queue/job.ts +++ b/packages/lib/server-only/queue/job.ts @@ -5,18 +5,26 @@ import { type SendDocumentOptions as SendCompletedDocumentOptions, sendCompletedEmail, } from '../document/send-completed-email'; +import { type SendPendingEmailOptions, sendPendingEmail } from '../document/send-pending-email'; type JobOptions = { 'send-completed-email': SendCompletedDocumentOptions; + 'send-pending-email': SendPendingEmailOptions; }; export const jobHandlers: { [K in keyof JobOptions]: WorkHandler; } = { - 'send-completed-email': async ({ data }) => { + 'send-completed-email': async ({ data: { documentId, requestMetadata } }) => { await sendCompletedEmail({ - documentId: data.documentId, - requestMetadata: data.requestMetadata, + documentId, + requestMetadata, + }); + }, + 'send-pending-email': async ({ data: { documentId, recipientId } }) => { + await sendPendingEmail({ + documentId, + recipientId, }); }, };