updates
This commit is contained in:
@@ -12,24 +12,19 @@ export async function scheduleEOIReminders() {
|
||||
|
||||
console.log('[EOI Reminders] Scheduling reminder tasks...');
|
||||
|
||||
// Dynamic import for node-cron to avoid ESM issues
|
||||
const cron = await import('node-cron');
|
||||
// Check every hour if it's time to send reminders
|
||||
setInterval(async () => {
|
||||
const now = new Date();
|
||||
const parisTime = new Date(now.toLocaleString('en-US', { timeZone: 'Europe/Paris' }));
|
||||
const hour = parisTime.getHours();
|
||||
const minute = parisTime.getMinutes();
|
||||
|
||||
// Schedule for 9am daily
|
||||
cron.schedule('0 9 * * *', async () => {
|
||||
console.log('[EOI Reminders] Running 9am reminder check...');
|
||||
await processReminders();
|
||||
}, {
|
||||
timezone: 'Europe/Paris'
|
||||
});
|
||||
|
||||
// Schedule for 4pm daily
|
||||
cron.schedule('0 16 * * *', async () => {
|
||||
console.log('[EOI Reminders] Running 4pm reminder check...');
|
||||
await processReminders();
|
||||
}, {
|
||||
timezone: 'Europe/Paris'
|
||||
});
|
||||
// Check if it's 9am or 4pm (16:00)
|
||||
if ((hour === 9 || hour === 16) && minute === 0) {
|
||||
console.log(`[EOI Reminders] Running ${hour === 9 ? '9am' : '4pm'} reminder check...`);
|
||||
await processReminders();
|
||||
}
|
||||
}, 60000); // Check every minute
|
||||
|
||||
tasksScheduled = true;
|
||||
console.log('[EOI Reminders] Tasks scheduled successfully');
|
||||
@@ -78,12 +73,14 @@ async function processReminders() {
|
||||
|
||||
async function sendReminder(interest: any) {
|
||||
try {
|
||||
// Use a full URL for the fetch since we're in a background task
|
||||
const baseUrl = process.env.NUXT_PUBLIC_SITE_URL || 'http://localhost:3000';
|
||||
const response = await $fetch<{
|
||||
success: boolean;
|
||||
remindersSent: number;
|
||||
results: any[];
|
||||
message?: string;
|
||||
}>('/api/eoi/send-reminders', {
|
||||
}>(`${baseUrl}/api/eoi/send-reminders`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-tag': '094ut234' // System tag for automated processes
|
||||
|
||||
@@ -28,7 +28,9 @@ export function scheduleEmailProcessing() {
|
||||
|
||||
async function processEmails() {
|
||||
try {
|
||||
const response = await $fetch('/api/email/process-sales-eois', {
|
||||
// Use a full URL for the fetch since we're in a background task
|
||||
const baseUrl = process.env.NUXT_PUBLIC_SITE_URL || 'http://localhost:3000';
|
||||
const response = await $fetch(`${baseUrl}/api/email/process-sales-eois`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-tag': '094ut234' // System tag for automated processes
|
||||
|
||||
Reference in New Issue
Block a user