mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 11:00:42 +00:00
fix(cron): key delivery dedupe by execution
This commit is contained in:
@@ -22,6 +22,7 @@ import {
|
||||
normalizeOptionalLowercaseString,
|
||||
normalizeOptionalString,
|
||||
} from "../../shared/string-coerce.js";
|
||||
import { createCronExecutionId } from "../run-id.js";
|
||||
import { hasScheduledNextRunAtMs } from "../service/jobs.js";
|
||||
import type { CronJob, CronRunTelemetry } from "../types.js";
|
||||
import type { DeliveryTargetResolution } from "./delivery-target.js";
|
||||
@@ -102,7 +103,6 @@ type DispatchCronDeliveryParams = {
|
||||
job: CronJob;
|
||||
agentId: string;
|
||||
agentSessionKey: string;
|
||||
runSessionId: string;
|
||||
runStartedAt: number;
|
||||
runEndedAt: number;
|
||||
timeoutMs: number;
|
||||
@@ -299,16 +299,18 @@ function getCompletedDirectCronDelivery(
|
||||
}
|
||||
|
||||
function buildDirectCronDeliveryIdempotencyKey(params: {
|
||||
runSessionId: string;
|
||||
jobId: string;
|
||||
runStartedAt: number;
|
||||
delivery: SuccessfulDeliveryTarget;
|
||||
}): string {
|
||||
const executionId = createCronExecutionId(params.jobId, params.runStartedAt);
|
||||
const threadId =
|
||||
params.delivery.threadId == null || params.delivery.threadId === ""
|
||||
? ""
|
||||
: String(params.delivery.threadId);
|
||||
const accountId = params.delivery.accountId?.trim() ?? "";
|
||||
const normalizedTo = normalizeDeliveryTarget(params.delivery.channel, params.delivery.to);
|
||||
return `cron-direct-delivery:v1:${params.runSessionId}:${params.delivery.channel}:${accountId}:${normalizedTo}:${threadId}`;
|
||||
return `cron-direct-delivery:v1:${executionId}:${params.delivery.channel}:${accountId}:${normalizedTo}:${threadId}`;
|
||||
}
|
||||
|
||||
function shouldQueueCronAwareness(job: CronJob, deliveryBestEffort: boolean): boolean {
|
||||
@@ -498,7 +500,8 @@ export async function dispatchCronDelivery(
|
||||
} = await loadDeliveryOutboundRuntime();
|
||||
const identity = resolveAgentOutboundIdentity(params.cfgWithAgentDefaults, params.agentId);
|
||||
const deliveryIdempotencyKey = buildDirectCronDeliveryIdempotencyKey({
|
||||
runSessionId: params.runSessionId,
|
||||
jobId: params.job.id,
|
||||
runStartedAt: params.runStartedAt,
|
||||
delivery,
|
||||
});
|
||||
try {
|
||||
|
||||
@@ -666,7 +666,6 @@ async function finalizeCronRun(params: {
|
||||
job: prepared.input.job,
|
||||
agentId: prepared.agentId,
|
||||
agentSessionKey: prepared.agentSessionKey,
|
||||
runSessionId: prepared.runSessionId,
|
||||
runStartedAt: execution.runStartedAt,
|
||||
runEndedAt: execution.runEndedAt,
|
||||
timeoutMs: prepared.timeoutMs,
|
||||
|
||||
Reference in New Issue
Block a user