Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(kv): improve backoff error message and inline documentation #27537

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cli/tsc/dts/lib.deno.unstable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ declare namespace Deno {
* executions. Each element in the array represents the number of milliseconds
* to wait before retrying the execution. For example, `[1000, 5000, 10000]`
* means that a failed execution will be retried at most 3 times, with 1
* second, 5 seconds, and 10 seconds delay between each retry.
* second, 5 seconds, and 10 seconds delay between each retry. There is a
* limit of 5 retries and a maximum interval of 1 hour (3600000 milliseconds).
*
* @category Cloud
* @experimental
Expand Down
8 changes: 6 additions & 2 deletions ext/kv/01_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,19 @@ const maxQueueBackoffInterval = 60 * 60 * 1000;

function validateBackoffSchedule(backoffSchedule: number[]) {
if (backoffSchedule.length > maxQueueBackoffIntervals) {
throw new TypeError("Invalid backoffSchedule");
throw new TypeError(
`Invalid backoffSchedule, max ${maxQueueBackoffIntervals} intervals allowed`,
);
}
for (let i = 0; i < backoffSchedule.length; ++i) {
const interval = backoffSchedule[i];
if (
interval < 0 || interval > maxQueueBackoffInterval ||
NumberIsNaN(interval)
) {
throw new TypeError("Invalid backoffSchedule");
throw new TypeError(
`Invalid backoffSchedule, interval at index ${i} is invalid`,
);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/kv_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1951,14 +1951,14 @@ dbTest("Invalid backoffSchedule", async (db) => {
await db.enqueue("foo", { backoffSchedule: [1, 1, 1, 1, 1, 1] });
},
TypeError,
"Invalid backoffSchedule",
"Invalid backoffSchedule, max 5 intervals allowed",
);
await assertRejects(
async () => {
await db.enqueue("foo", { backoffSchedule: [3600001] });
},
TypeError,
"Invalid backoffSchedule",
"Invalid backoffSchedule, interval at index 0 is invalid",
);
});

Expand Down
Loading