feat: auto-trigger scheduled agents + fix stale nextRun display
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 41s

- Add background scheduler in entrypoint: calls /api/cron/agents every
  5 minutes to trigger due agents automatically
- Recalculate stale nextRun (past dates) in getAgents() so the display
  always shows a future time
- Agent card shows "En attente de déclenchement" instead of "il y a X"
  when nextRun is in the past

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-04-26 12:28:38 +02:00
parent 5d960cad4e
commit 17e4a58da2
5 changed files with 34 additions and 1 deletions

View File

@@ -206,6 +206,26 @@ export async function getAgents() {
orderBy: { createdAt: 'desc' }
})
// Fix stale nextRun: recalculate if in the past for scheduled agents
const now = new Date()
for (const agent of agents) {
if (agent.frequency !== 'manual' && agent.nextRun && new Date(agent.nextRun) < now) {
const nextRun = calculateNextRun({
frequency: agent.frequency,
scheduledTime: agent.scheduledTime,
scheduledDay: agent.scheduledDay,
timezone: agent.timezone,
})
if (nextRun) {
await prisma.agent.update({
where: { id: agent.id },
data: { nextRun },
})
agent.nextRun = nextRun
}
}
}
return agents
} catch (error) {
console.error('Error fetching agents:', error)