




















@@ -354,11 +354,26 @@ function assertDeliverySupport(job: Pick<CronJob, "sessionTarget" | "delivery">)
354354}
355355}
356356357+function hasConcreteFailureDestination(
358+destination: CronDelivery["failureDestination"] | undefined,
359+): boolean {
360+return Boolean(
361+destination &&
362+(destination.channel !== undefined ||
363+destination.to !== undefined ||
364+destination.accountId !== undefined ||
365+destination.mode !== undefined),
366+);
367+}
368+357369function assertFailureDestinationSupport(job: Pick<CronJob, "sessionTarget" | "delivery">) {
358370const failureDestination = job.delivery?.failureDestination;
359371if (!failureDestination) {
360372return;
361373}
374+if (!hasConcreteFailureDestination(failureDestination)) {
375+return;
376+}
362377if (job.sessionTarget === "main" && job.delivery?.mode !== "webhook") {
363378throw new Error(
364379'cron delivery.failureDestination is only supported for sessionTarget="isolated" unless delivery.mode="webhook"',
@@ -820,14 +835,18 @@ export function applyJobPatch(
820835if (
821836job.sessionTarget === "main" &&
822837job.delivery?.mode !== "webhook" &&
823-job.delivery?.failureDestination
838+hasConcreteFailureDestination(job.delivery?.failureDestination)
824839) {
825840throw new Error(
826841'cron delivery.failureDestination is only supported for sessionTarget="isolated" unless delivery.mode="webhook"',
827842);
828843}
829844if (job.sessionTarget === "main" && job.delivery?.mode !== "webhook") {
830-job.delivery = undefined;
845+const failureDestination = job.delivery?.failureDestination;
846+job.delivery =
847+failureDestination && !hasConcreteFailureDestination(failureDestination)
848+ ? { mode: "none", failureDestination }
849+ : undefined;
831850}
832851if (patch.state) {
833852job.state = { ...job.state, ...patch.state };
@@ -981,12 +1000,21 @@ function mergeCronDelivery(
9811000} else {
9821001const existingFd = next.failureDestination;
9831002const patchFd = patch.failureDestination;
984-const nextFd: typeof next.failureDestination = {
985-channel: existingFd?.channel,
986-to: existingFd?.to,
987-accountId: existingFd?.accountId,
988-mode: existingFd?.mode,
989-};
1003+const nextFd: typeof next.failureDestination = {};
1004+if (existingFd) {
1005+if (Object.hasOwn(existingFd, "channel")) {
1006+nextFd.channel = existingFd.channel;
1007+}
1008+if (Object.hasOwn(existingFd, "to")) {
1009+nextFd.to = existingFd.to;
1010+}
1011+if (Object.hasOwn(existingFd, "accountId")) {
1012+nextFd.accountId = existingFd.accountId;
1013+}
1014+if (Object.hasOwn(existingFd, "mode")) {
1015+nextFd.mode = existingFd.mode;
1016+}
1017+}
9901018if (patchFd) {
9911019if ("channel" in patchFd) {
9921020const channel = normalizeOptionalString(patchFd.channel) ?? "";
@@ -1006,10 +1034,10 @@ function mergeCronDelivery(
10061034}
10071035}
10081036const hasFailureDestination =
1009-nextFd.channel !== undefined ||
1010-nextFd.to !== undefined ||
1011-nextFd.accountId !== undefined ||
1012-nextFd.mode !== undefined;
1037+Object.hasOwn(nextFd, "channel") ||
1038+Object.hasOwn(nextFd, "to") ||
1039+Object.hasOwn(nextFd, "accountId") ||
1040+Object.hasOwn(nextFd, "mode");
10131041next.failureDestination = hasFailureDestination ? nextFd : undefined;
10141042}
10151043}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。