mirror of
https://github.com/documenso/documenso.git
synced 2026-08-25 07:42:28 +10:00
feat: per-recipient envelope expiration (#2519)
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { DocumentStatus, SigningStatus } from '@prisma/client';
|
||||
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
import { jobs } from '../../client';
|
||||
import type { JobRunIO } from '../../client/_internal/job';
|
||||
import type { TExpireRecipientsSweepJobDefinition } from './expire-recipients-sweep';
|
||||
|
||||
export const run = async ({
|
||||
io,
|
||||
}: {
|
||||
payload: TExpireRecipientsSweepJobDefinition;
|
||||
io: JobRunIO;
|
||||
}) => {
|
||||
const now = new Date();
|
||||
|
||||
const expiredRecipients = await prisma.recipient.findMany({
|
||||
where: {
|
||||
expiresAt: {
|
||||
lte: now,
|
||||
},
|
||||
expirationNotifiedAt: null,
|
||||
signingStatus: {
|
||||
notIn: [SigningStatus.SIGNED, SigningStatus.REJECTED],
|
||||
},
|
||||
envelope: {
|
||||
status: DocumentStatus.PENDING,
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
take: 1000, // Limit to 1000 to avoid long-running jobs. Will be picked up in the next run if there are more.
|
||||
});
|
||||
|
||||
if (expiredRecipients.length === 0) {
|
||||
io.logger.info('No expired recipients found');
|
||||
return;
|
||||
}
|
||||
|
||||
io.logger.info(`Found ${expiredRecipients.length} expired recipients`);
|
||||
|
||||
await Promise.allSettled(
|
||||
expiredRecipients.map(async (recipient) => {
|
||||
await jobs.triggerJob({
|
||||
name: 'internal.process-recipient-expired',
|
||||
payload: {
|
||||
recipientId: recipient.id,
|
||||
},
|
||||
});
|
||||
}),
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user