updates
This commit is contained in:
parent
218705da52
commit
bd07939c3d
|
|
@ -2,18 +2,28 @@ import { scheduleEOIReminders } from '~/server/tasks/eoi-reminders';
|
|||
import { scheduleEmailProcessing } from '~/server/tasks/process-sales-emails';
|
||||
|
||||
export default defineNitroPlugin((nitroApp) => {
|
||||
console.log('[Plugin] Initializing automated tasks...');
|
||||
|
||||
// Schedule EOI reminders when server starts
|
||||
console.log('[Plugin] Initializing EOI reminder scheduler...');
|
||||
|
||||
// Add a small delay to ensure all services are ready
|
||||
setTimeout(() => {
|
||||
scheduleEOIReminders();
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
await scheduleEOIReminders();
|
||||
} catch (error) {
|
||||
console.error('[Plugin] Failed to schedule EOI reminders:', error);
|
||||
}
|
||||
}, 5000);
|
||||
|
||||
// Schedule email processing for EOI attachments
|
||||
console.log('[Plugin] Initializing email processing scheduler...');
|
||||
|
||||
setTimeout(() => {
|
||||
scheduleEmailProcessing();
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
await scheduleEmailProcessing();
|
||||
} catch (error) {
|
||||
console.error('[Plugin] Failed to schedule email processing:', error);
|
||||
}
|
||||
}, 7000);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
import cron from 'node-cron';
|
||||
import { getInterests } from '~/server/utils/nocodb';
|
||||
import { checkDocumentSignatureStatus } from '~/server/utils/documeso';
|
||||
|
||||
// Track if tasks are already scheduled
|
||||
let tasksScheduled = false;
|
||||
|
||||
export function scheduleEOIReminders() {
|
||||
export async function scheduleEOIReminders() {
|
||||
if (tasksScheduled) {
|
||||
console.log('[EOI Reminders] Tasks already scheduled');
|
||||
return;
|
||||
|
|
@ -13,6 +12,9 @@ export function scheduleEOIReminders() {
|
|||
|
||||
console.log('[EOI Reminders] Scheduling reminder tasks...');
|
||||
|
||||
// Dynamic import for node-cron to avoid ESM issues
|
||||
const cron = await import('node-cron');
|
||||
|
||||
// Schedule for 9am daily
|
||||
cron.schedule('0 9 * * *', async () => {
|
||||
console.log('[EOI Reminders] Running 9am reminder check...');
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { simpleParser } from 'mailparser';
|
||||
import type { ParsedMail } from 'mailparser';
|
||||
import Imap from 'imap';
|
||||
const Imap = require('imap');
|
||||
|
||||
export type { ParsedMail };
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ export async function parseEmail(emailContent: string): Promise<ParsedMail> {
|
|||
return await simpleParser(emailContent);
|
||||
}
|
||||
|
||||
export function getIMAPConnection(credentials: EmailCredentials): Promise<Imap> {
|
||||
export function getIMAPConnection(credentials: EmailCredentials): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const imap = new Imap({
|
||||
user: credentials.user,
|
||||
|
|
@ -41,7 +41,7 @@ export function getIMAPConnection(credentials: EmailCredentials): Promise<Imap>
|
|||
});
|
||||
}
|
||||
|
||||
export function searchEmails(imap: Imap, criteria: any[]): Promise<number[]> {
|
||||
export function searchEmails(imap: any, criteria: any[]): Promise<number[]> {
|
||||
return new Promise((resolve, reject) => {
|
||||
imap.search(criteria, (err: Error | null, results: number[]) => {
|
||||
if (err) reject(err);
|
||||
|
|
@ -50,7 +50,7 @@ export function searchEmails(imap: Imap, criteria: any[]): Promise<number[]> {
|
|||
});
|
||||
}
|
||||
|
||||
export function fetchEmail(imap: Imap, msgId: number, options: any): Promise<string> {
|
||||
export function fetchEmail(imap: any, msgId: number, options: any): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
let emailData = '';
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue