mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 10:33:54 +00:00
feat(kv) queue implementation (#19459)
Extend the unstable `Deno.Kv` API to support queues.
This commit is contained in:
parent
d451abfc91
commit
fd9d6baea3
10 changed files with 1203 additions and 51 deletions
59
cli/tsc/dts/lib.deno.unstable.d.ts
vendored
59
cli/tsc/dts/lib.deno.unstable.d.ts
vendored
|
@ -1914,6 +1914,14 @@ declare namespace Deno {
|
|||
* checks pass during the commit.
|
||||
*/
|
||||
delete(key: KvKey): this;
|
||||
/**
|
||||
* Add to the operation a mutation that enqueues a value into the queue
|
||||
* if all checks pass during the commit.
|
||||
*/
|
||||
enqueue(
|
||||
value: unknown,
|
||||
options?: { delay?: number; keysIfUndelivered?: Deno.KvKey[] },
|
||||
): this;
|
||||
/**
|
||||
* Commit the operation to the KV store. Returns a value indicating whether
|
||||
* checks passed and mutations were performed. If the operation failed
|
||||
|
@ -2087,6 +2095,57 @@ declare namespace Deno {
|
|||
options?: KvListOptions,
|
||||
): KvListIterator<T>;
|
||||
|
||||
/**
|
||||
* Add a value into the database queue to be delivered to the queue
|
||||
* listener via {@linkcode Deno.Kv.listenQueue}.
|
||||
*
|
||||
* ```ts
|
||||
* const db = await Deno.openKv();
|
||||
* await db.enqueue("bar");
|
||||
* ```
|
||||
*
|
||||
* The `delay` option can be used to specify the delay (in milliseconds)
|
||||
* of the value delivery. The default delay is 0, which means immediate
|
||||
* delivery.
|
||||
*
|
||||
* ```ts
|
||||
* const db = await Deno.openKv();
|
||||
* await db.enqueue("bar", { delay: 60000 });
|
||||
* ```
|
||||
*
|
||||
* The `keysIfUndelivered` option can be used to specify the keys to
|
||||
* be set if the value is not successfully delivered to the queue
|
||||
* listener after several attempts. The values are set to the value of
|
||||
* the queued message.
|
||||
*
|
||||
* ```ts
|
||||
* const db = await Deno.openKv();
|
||||
* await db.enqueue("bar", { keysIfUndelivered: [["foo", "bar"]] });
|
||||
* ```
|
||||
*/
|
||||
enqueue(
|
||||
value: unknown,
|
||||
options?: { delay?: number; keysIfUndelivered?: Deno.KvKey[] },
|
||||
): Promise<KvCommitResult>;
|
||||
|
||||
/**
|
||||
* Listen for queue values to be delivered from the database queue, which
|
||||
* were enqueued with {@linkcode Deno.Kv.enqueue}. The provided handler
|
||||
* callback is invoked on every dequeued value. A failed callback
|
||||
* invocation is automatically retried multiple times until it succeeds
|
||||
* or until the maximum number of retries is reached.
|
||||
*
|
||||
* ```ts
|
||||
* const db = await Deno.openKv();
|
||||
* db.listenQueue(async (msg: unknown) => {
|
||||
* await db.set(["foo"], msg);
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
listenQueue(
|
||||
handler: (value: unknown) => Promise<void> | void,
|
||||
): Promise<void>;
|
||||
|
||||
/**
|
||||
* Create a new {@linkcode Deno.AtomicOperation} object which can be used to
|
||||
* perform an atomic transaction on the database. This does not perform any
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue