Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 50a409c

Browse files
authored
🐛 fix: update the agent cron job update way (lobehub#11877)
* feat: add the setAgentBuilderContent tools into agent group builder to slove setEditor not work * feat: update the system prompt * feat: add the maxtools result call lenght in agent config * fix: update the cronJob Update config way
1 parent eaf8cae commit 50a409c

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

packages/database/src/models/agentCronJob.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,35 @@ export class AgentCronJobModel {
7979

8080
// Update cron job
8181
async update(id: string, data: UpdateAgentCronJobData): Promise<AgentCronJob | null> {
82+
// Check if critical fields (cronPattern or timezone) are being changed
83+
// If so, reset lastExecutedAt to allow immediate execution with new schedule
84+
let shouldResetLastExecuted = false;
85+
86+
if (data?.cronPattern !== undefined || data?.timezone !== undefined) {
87+
const existing = await this.findById(id);
88+
if (existing && (
89+
(data?.cronPattern !== undefined && data?.cronPattern !== existing.cronPattern) ||
90+
(data?.timezone !== undefined && data?.timezone !== existing.timezone)
91+
)) {
92+
shouldResetLastExecuted = true;
93+
}
94+
}
95+
96+
const updateData: Record<string, unknown> = {
97+
...data,
98+
...(shouldResetLastExecuted ? { lastExecutedAt: null } : {}),
99+
updatedAt: new Date(),
100+
};
101+
102+
// When maxExecutions is updated, reset remainingExecutions to match
103+
// This ensures the new limit takes effect immediately
104+
if (data?.maxExecutions !== undefined) {
105+
updateData.remainingExecutions = data.maxExecutions;
106+
}
107+
82108
const result = await this.db
83109
.update(agentCronJobs)
84-
.set({
85-
...data,
86-
updatedAt: new Date(),
87-
})
110+
.set(updateData)
88111
.where(and(eq(agentCronJobs.id, id), eq(agentCronJobs.userId, this.userId)))
89112
.returning();
90113

0 commit comments

Comments
 (0)