Skip to content

Commit 67258d1

Browse files
giodl73-reporoot
authored andcommitted
refactor(claws): keep pending cron recovery unchanged
1 parent 737a7b0 commit 67258d1

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

‎src/claws/cron.test.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,17 @@ describe("installClawCronJobs", () => {
264264
cronJobs: [{ status: "pending" }],
265265
});
266266

267-
const [pending] = readClawCronRefs("worker-two", { env: current.env });
268267
const refs = await installClawCronJobs(current.plan, {
269268
env: current.env,
270269
gateway: {
271270
add,
272271
list: vi.fn().mockResolvedValue({
273-
jobs: [listedCronJob("worker-two", pending!, "scheduler-after-lost-response")],
272+
jobs: [
273+
{
274+
id: "scheduler-after-lost-response",
275+
declarationKey: "claw:worker-two:daily-report",
276+
},
277+
],
274278
}),
275279
},
276280
});

‎src/claws/cron.ts‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export function clawCronSchedulerJobFromResult(value: unknown): { id: string } |
186186
return undefined;
187187
}
188188

189-
function schedulerJobByDeclarationKey(
189+
function schedulerJobRecordByDeclarationKey(
190190
value: unknown,
191191
declarationKey: string,
192192
): Record<string, unknown> | undefined {
@@ -208,6 +208,14 @@ function schedulerJobByDeclarationKey(
208208
return match;
209209
}
210210

211+
function schedulerJobByDeclarationKey(
212+
value: unknown,
213+
declarationKey: string,
214+
): { id: string } | undefined {
215+
const match = schedulerJobRecordByDeclarationKey(value, declarationKey);
216+
return match ? { id: match.id as string } : undefined;
217+
}
218+
211219
export function clawCronGatewayInput(
212220
agentId: string,
213221
ref: PersistedClawCronRef,
@@ -328,7 +336,7 @@ export async function installClawCronJobs(
328336
await options.gateway.waitUntilAgentAvailable?.(plan.agent.finalId);
329337
agentAvailable = true;
330338
}
331-
const listedJob = schedulerJobByDeclarationKey(
339+
const listedJob = schedulerJobRecordByDeclarationKey(
332340
await options.gateway.list(plan.agent.finalId),
333341
pending.declarationKey,
334342
);
@@ -362,18 +370,10 @@ export async function installClawCronJobs(
362370
agentAvailable = true;
363371
}
364372
if (options.gateway.list) {
365-
const listedJob = schedulerJobByDeclarationKey(
373+
result = schedulerJobByDeclarationKey(
366374
await options.gateway.list(plan.agent.finalId),
367375
pending.declarationKey,
368376
);
369-
if (listedJob) {
370-
if (!clawCronGatewayJobMatchesRef(plan.agent.finalId, pending, listedJob)) {
371-
throw new Error(
372-
`Cron declaration ${JSON.stringify(pending.manifestId)} changed after an ambiguous write.`,
373-
);
374-
}
375-
result = { id: listedJob.id as string };
376-
}
377377
}
378378
result ??= clawCronSchedulerJobFromResult(
379379
await options.gateway.add(clawCronGatewayInput(plan.agent.finalId, pending)),

0 commit comments

Comments
 (0)