1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 04:52:26 -05:00

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

Ref: #27536
This commit is contained in:
Kitson Kelly 2025-01-04 10:04:14 +11:00 committed by GitHub
parent 89c92b84fa
commit 7cabd02c59
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 5 deletions

View file

@ -293,7 +293,8 @@ declare namespace Deno {
* executions. Each element in the array represents the number of milliseconds * executions. Each element in the array represents the number of milliseconds
* to wait before retrying the execution. For example, `[1000, 5000, 10000]` * 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 * 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 * @category Cloud
* @experimental * @experimental

View file

@ -77,7 +77,9 @@ const maxQueueBackoffInterval = 60 * 60 * 1000;
function validateBackoffSchedule(backoffSchedule: number[]) { function validateBackoffSchedule(backoffSchedule: number[]) {
if (backoffSchedule.length > maxQueueBackoffIntervals) { 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) { for (let i = 0; i < backoffSchedule.length; ++i) {
const interval = backoffSchedule[i]; const interval = backoffSchedule[i];
@ -85,7 +87,9 @@ function validateBackoffSchedule(backoffSchedule: number[]) {
interval < 0 || interval > maxQueueBackoffInterval || interval < 0 || interval > maxQueueBackoffInterval ||
NumberIsNaN(interval) NumberIsNaN(interval)
) { ) {
throw new TypeError("Invalid backoffSchedule"); throw new TypeError(
`Invalid backoffSchedule, interval at index ${i} is invalid`,
);
} }
} }
} }

View file

@ -1951,14 +1951,14 @@ dbTest("Invalid backoffSchedule", async (db) => {
await db.enqueue("foo", { backoffSchedule: [1, 1, 1, 1, 1, 1] }); await db.enqueue("foo", { backoffSchedule: [1, 1, 1, 1, 1, 1] });
}, },
TypeError, TypeError,
"Invalid backoffSchedule", "Invalid backoffSchedule, max 5 intervals allowed",
); );
await assertRejects( await assertRejects(
async () => { async () => {
await db.enqueue("foo", { backoffSchedule: [3600001] }); await db.enqueue("foo", { backoffSchedule: [3600001] });
}, },
TypeError, TypeError,
"Invalid backoffSchedule", "Invalid backoffSchedule, interval at index 0 is invalid",
); );
}); });