fix: remove nextRun recalculation from getAgents() that blocked cron
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 42s
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 42s
The getAgents() function was recalculating nextRun to future dates when it found past values. This prevented the cron scheduler from ever finding due agents (nextRun <= now was always false since getAgents had already pushed it to the future). Also fix toast polling: use null sentinel for agents without initial actions so first execution is still detected. Limit cron to 3 agents per cycle and add logging. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -206,26 +206,6 @@ 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)
|
||||
|
||||
Reference in New Issue
Block a user