diff --git a/memento-note/app/actions/agent-actions.ts b/memento-note/app/actions/agent-actions.ts index 306b561..58449a5 100644 --- a/memento-note/app/actions/agent-actions.ts +++ b/memento-note/app/actions/agent-actions.ts @@ -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) diff --git a/memento-note/components/agents/agent-card.tsx b/memento-note/components/agents/agent-card.tsx index 84a98c1..61961a5 100644 --- a/memento-note/components/agents/agent-card.tsx +++ b/memento-note/components/agents/agent-card.tsx @@ -202,7 +202,9 @@ export function AgentCard({ agent, onEdit, onRefresh, onToggle }: AgentCardProps {t('agents.schedule.nextRun')}{' '} {mounted - ? formatDistanceToNow(new Date(agent.nextRun), { addSuffix: true, locale: dateLocale }) + ? new Date(agent.nextRun) > new Date() + ? formatDistanceToNow(new Date(agent.nextRun), { addSuffix: true, locale: dateLocale }) + : t('agents.schedule.pending') : new Date(agent.nextRun).toISOString().split('T')[0]} )} diff --git a/memento-note/docker-entrypoint.sh b/memento-note/docker-entrypoint.sh index 991cf74..539c9c3 100644 --- a/memento-note/docker-entrypoint.sh +++ b/memento-note/docker-entrypoint.sh @@ -4,5 +4,14 @@ set -e echo "Running Prisma migrations..." node ./node_modules/prisma/build/index.js migrate deploy +# Background scheduler: call /api/cron/agents every 5 minutes +( + sleep 60 + while true; do + wget -q -O /dev/null --post-data='' "http://localhost:3000/api/cron/agents" 2>/dev/null || true + sleep 300 + done +) & + echo "Starting server..." exec node server.js diff --git a/memento-note/locales/en.json b/memento-note/locales/en.json index 6b08ed1..e6df991 100644 --- a/memento-note/locales/en.json +++ b/memento-note/locales/en.json @@ -1256,6 +1256,7 @@ }, "schedule": { "nextRun": "Next run", + "pending": "Pending trigger", "time": "Time", "dayOfWeek": "Day of week", "dayOfMonth": "Day of month", diff --git a/memento-note/locales/fr.json b/memento-note/locales/fr.json index 53b5d91..13777ef 100644 --- a/memento-note/locales/fr.json +++ b/memento-note/locales/fr.json @@ -1252,6 +1252,7 @@ }, "schedule": { "nextRun": "Prochaine exécution", + "pending": "En attente de déclenchement", "time": "Heure", "dayOfWeek": "Jour de la semaine", "dayOfMonth": "Jour du mois",