mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
feat: update reminder email jobs to support multiple intervals; remove monthly and weekly jobs
This commit is contained in:
@ -18,7 +18,13 @@ export const SEND_DAILY_REMINDER_EMAIL_JOB = {
|
|||||||
|
|
||||||
await handler.run({
|
await handler.run({
|
||||||
io,
|
io,
|
||||||
interval: DocumentReminderInterval.DAILY,
|
intervals: [
|
||||||
|
DocumentReminderInterval.DAILY,
|
||||||
|
DocumentReminderInterval.EVERY_3_DAYS,
|
||||||
|
DocumentReminderInterval.WEEKLY,
|
||||||
|
DocumentReminderInterval.EVERY_2_WEEKS,
|
||||||
|
DocumentReminderInterval.MONTHLY,
|
||||||
|
],
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
} as const satisfies JobDefinition<typeof SEND_DAILY_REMINDER_EMAIL_JOB_ID>;
|
} as const satisfies JobDefinition<typeof SEND_DAILY_REMINDER_EMAIL_JOB_ID>;
|
||||||
|
|||||||
@ -10,8 +10,7 @@ export const SEND_HOURLY_REMINDER_EMAIL_JOB = {
|
|||||||
version: '1.0.0',
|
version: '1.0.0',
|
||||||
trigger: {
|
trigger: {
|
||||||
type: 'cron',
|
type: 'cron',
|
||||||
// schedule: '0 * * * *',
|
schedule: '0 * * * *',
|
||||||
schedule: '*/2 * * * *',
|
|
||||||
name: SEND_HOURLY_REMINDER_EMAIL_JOB_ID,
|
name: SEND_HOURLY_REMINDER_EMAIL_JOB_ID,
|
||||||
},
|
},
|
||||||
handler: async ({ io }) => {
|
handler: async ({ io }) => {
|
||||||
@ -19,7 +18,11 @@ export const SEND_HOURLY_REMINDER_EMAIL_JOB = {
|
|||||||
|
|
||||||
await handler.run({
|
await handler.run({
|
||||||
io,
|
io,
|
||||||
interval: DocumentReminderInterval.EVERY_1_HOUR,
|
intervals: [
|
||||||
|
DocumentReminderInterval.EVERY_1_HOUR,
|
||||||
|
DocumentReminderInterval.EVERY_6_HOURS,
|
||||||
|
DocumentReminderInterval.EVERY_12_HOURS,
|
||||||
|
],
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
} as const satisfies JobDefinition<typeof SEND_HOURLY_REMINDER_EMAIL_JOB_ID>;
|
} as const satisfies JobDefinition<typeof SEND_HOURLY_REMINDER_EMAIL_JOB_ID>;
|
||||||
|
|||||||
@ -1,24 +0,0 @@
|
|||||||
import { DocumentReminderInterval } from '@documenso/prisma/client';
|
|
||||||
|
|
||||||
import type { JobDefinition } from '../../client/_internal/job';
|
|
||||||
|
|
||||||
const SEND_MONTHLY_REMINDER_EMAIL_JOB_ID = 'send.monthly.reminder.email';
|
|
||||||
|
|
||||||
export const SEND_MONTHLY_REMINDER_EMAIL_JOB = {
|
|
||||||
id: SEND_MONTHLY_REMINDER_EMAIL_JOB_ID,
|
|
||||||
name: 'Send Monthly Reminder Email',
|
|
||||||
version: '1.0.0',
|
|
||||||
trigger: {
|
|
||||||
type: 'cron',
|
|
||||||
schedule: '0 0 1 * *',
|
|
||||||
name: SEND_MONTHLY_REMINDER_EMAIL_JOB_ID,
|
|
||||||
},
|
|
||||||
handler: async ({ io }) => {
|
|
||||||
const handler = await import('./send-reminder.handler');
|
|
||||||
|
|
||||||
await handler.run({
|
|
||||||
io,
|
|
||||||
interval: DocumentReminderInterval.MONTHLY,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
} as const satisfies JobDefinition<typeof SEND_MONTHLY_REMINDER_EMAIL_JOB_ID>;
|
|
||||||
@ -21,21 +21,22 @@ import type { JobRunIO } from '../../client/_internal/job';
|
|||||||
|
|
||||||
export type SendReminderHandlerOptions = {
|
export type SendReminderHandlerOptions = {
|
||||||
io: JobRunIO;
|
io: JobRunIO;
|
||||||
interval: DocumentReminderInterval;
|
intervals: DocumentReminderInterval[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function run({ io, interval }: SendReminderHandlerOptions) {
|
export async function run({ io, intervals }: SendReminderHandlerOptions) {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
const intervalsString = intervals.join(',').toLowerCase();
|
||||||
|
|
||||||
const documentsToSendReminders = await io.runTask(
|
const documentsToSendReminders = await io.runTask(
|
||||||
`find-documents-for-${interval.toLocaleUpperCase()}-reminder`,
|
`find-documents-for-${intervalsString}-reminder`,
|
||||||
async () => {
|
async () => {
|
||||||
const documents = await prisma.document.findMany({
|
const documents = await prisma.document.findMany({
|
||||||
where: {
|
where: {
|
||||||
status: DocumentStatus.PENDING,
|
status: DocumentStatus.PENDING,
|
||||||
documentMeta: {
|
documentMeta: {
|
||||||
reminderInterval: {
|
reminderInterval: {
|
||||||
equals: interval,
|
in: intervals,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
deletedAt: null,
|
deletedAt: null,
|
||||||
@ -72,7 +73,7 @@ export async function run({ io, interval }: SendReminderHandlerOptions) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
io.logger.info(
|
io.logger.info(
|
||||||
`Found ${filteredDocuments.length} documents after filtering for interval ${interval}.`,
|
`Found ${filteredDocuments.length} documents after filtering for interval ${intervalsString}.`,
|
||||||
filteredDocuments.map((d) => ({ id: d.id })),
|
filteredDocuments.map((d) => ({ id: d.id })),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -81,12 +82,12 @@ export async function run({ io, interval }: SendReminderHandlerOptions) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (documentsToSendReminders.length === 0) {
|
if (documentsToSendReminders.length === 0) {
|
||||||
io.logger.info(`No documents found needing ${interval.toLocaleUpperCase()} reminders.`);
|
io.logger.info(`No documents found needing ${intervalsString} reminders.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
io.logger.info(
|
io.logger.info(
|
||||||
`Found ${documentsToSendReminders.length} documents needing ${interval.toLocaleUpperCase()} reminders.`,
|
`Found ${documentsToSendReminders.length} documents needing ${intervalsString} reminders.`,
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const document of documentsToSendReminders) {
|
for (const document of documentsToSendReminders) {
|
||||||
|
|||||||
@ -1,24 +0,0 @@
|
|||||||
import { DocumentReminderInterval } from '@documenso/prisma/client';
|
|
||||||
|
|
||||||
import type { JobDefinition } from '../../client/_internal/job';
|
|
||||||
|
|
||||||
const SEND_WEEKLY_REMINDER_EMAIL_JOB_ID = 'send.weekly.reminder.email';
|
|
||||||
|
|
||||||
export const SEND_WEEKLY_REMINDER_EMAIL_JOB = {
|
|
||||||
id: SEND_WEEKLY_REMINDER_EMAIL_JOB_ID,
|
|
||||||
name: 'Send Weekly Reminder Email',
|
|
||||||
version: '1.0.0',
|
|
||||||
trigger: {
|
|
||||||
type: 'cron',
|
|
||||||
schedule: '0 0 * * 0',
|
|
||||||
name: SEND_WEEKLY_REMINDER_EMAIL_JOB_ID,
|
|
||||||
},
|
|
||||||
handler: async ({ io }) => {
|
|
||||||
const handler = await import('./send-reminder.handler');
|
|
||||||
|
|
||||||
await handler.run({
|
|
||||||
io,
|
|
||||||
interval: DocumentReminderInterval.WEEKLY,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
} as const satisfies JobDefinition<typeof SEND_WEEKLY_REMINDER_EMAIL_JOB_ID>;
|
|
||||||
Reference in New Issue
Block a user