I'm encountering an issue with Deno Queue in my Deno Deploy project, and I'm hoping to get some guidance on it. Here's a brief summary of the problem:
Problem description:
In my Deno Deploy project, I'm trying to use Deno Queue, but it's not behaving as expected in production. During development, I received a log message stating that Deno Queue features are enabled in production, but I'm unable to get it to work as intended in the production environment.
Code Sample:
Here's the code I've written for this functionality:
import type { ShorterOptions } from "shorter/lib/shorter/mod.ts";
import { shorter } from "shorter/lib/shorter/mod.ts";
/**
* TTLMessage is a message received from the TTL channel.
*/
export interface TTLMessage {
channel: "ttl";
data: {
alias: string;
actor: ShorterOptions["actor"];
};
}
/**
* isTTLMessage checks if the message is a TTL message.
*/
export function isTTLMessage(m: unknown): m is TTLMessage {
return (m as TTLMessage).channel === "ttl";
}
/**
* makeTTLMessageListener makes a TTL message listener.
*/
export function makeTTLMessageListener(
githubPAT: string,
) {
/**
* listenToTTLChannel listens to the TTL channel.
*/
return async function listenToTTLChannel(m: unknown) {
if (!isTTLMessage(m)) {
return;
}
// Remove the shortlink from persisted storage.
await shorter({
githubPAT,
actor: m.data.actor,
// Omitting the destination will remove the alias.
data: { alias: m.data.alias },
})
.catch((error) => {
if (error instanceof Error) {
console.error(error);
}
});
};
}
/**
* addTTLMessage adds a TTL message to the TTL channel.
*
* See:
* https://docs.deno.com/kv/manual/queue_overview#queues-on-deno-deploy
*/
export async function addTTLMessage(
kv: Deno.Kv,
data: TTLMessage["data"],
delay: number,
) {
return await kv.enqueue(
{ channel: "ttl", data },
{ delay },
);
}
In this code, I've implemented functions for handling TTL (Time To Live) messages using Deno Queue. However, when I try to use this code in production, it doesn't work as expected.
I'm wondering if anyone has experienced a similar issue or if there's something specific I should be aware of when using Deno Queue in a production environment.
Thanks in advance!