feat: implement agent scheduled execution with cron and time picker
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 1m9s
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 1m9s
- Add scheduledTime, scheduledDay, timezone fields to Agent schema - Create calculateNextRun() helper with timezone-aware scheduling - Add POST /api/cron/agents endpoint for external scheduler - Calculate nextRun on agent create, update, and after execution - Add time/day picker in agent form (daily/weekly/monthly) - Show "Next run" countdown in agent card - Add i18n keys for schedule UI (FR + EN) External scheduler (N8N, Vercel Cron) should call /api/cron/agents every 5-15 min. Requires `prisma db push` to apply schema changes. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,7 @@ import { toolRegistry } from '../tools'
|
||||
import { sendEmail } from '@/lib/mail'
|
||||
import { getAgentEmailTemplate } from '@/lib/agent-email-template'
|
||||
import { extractAndDownloadImages, extractImageUrlsFromHtml, downloadImage } from '../tools/extract-images'
|
||||
import { calculateNextRun } from '@/lib/agents/schedule'
|
||||
|
||||
// Import tools for side-effect registration
|
||||
import '../tools'
|
||||
@@ -1094,9 +1095,19 @@ export async function executeAgent(agentId: string, userId: string, promptOverri
|
||||
}
|
||||
}
|
||||
|
||||
const nextRunUpdate: Record<string, Date | null> = {}
|
||||
if (agent.frequency !== 'manual') {
|
||||
nextRunUpdate.nextRun = calculateNextRun({
|
||||
frequency: agent.frequency,
|
||||
scheduledTime: agent.scheduledTime,
|
||||
scheduledDay: agent.scheduledDay,
|
||||
timezone: agent.timezone,
|
||||
})
|
||||
}
|
||||
|
||||
await prisma.agent.update({
|
||||
where: { id: agentId },
|
||||
data: { lastRun: new Date() }
|
||||
data: { lastRun: new Date(), ...nextRunUpdate }
|
||||
})
|
||||
|
||||
if (result.success && agent.notifyEmail) {
|
||||
|
||||
Reference in New Issue
Block a user