D
Deno

help

Deno Deploy Queue trouble in production

EEthanThatOneKid10/4/2023
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 },
);
}
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!
EEthanThatOneKid10/4/2023
I have been referencing the recent blog post https://deno.com/blog/queues and all the links within it.
Deno Blog
Announcing Deno Queues
Introducing Deno Queues - zero config, scalable messaging with a guaranteed at-least-once delivery. This new primitive builds on the foundation set by Deno KV, and is available today in the Deno JavaScript runtime and Deno Deploy.
Ccknight10/4/2023
Can you elaborate on what isn't working as expected?
EEthanThatOneKid10/4/2023
It never executes. I tested with various delays.
Ccknight10/4/2023
Does it deliver without a delay? And does it work locally?
EEthanThatOneKid10/4/2023
if (import.meta.main) {
await main();
}

/**
* main is the entrypoint for the Shorter application command.
*/
export async function main() {
// Set up queue listener.
const kv = await Deno.openKv();
kv.listenQueue(makeTTLMessageListener(GITHUB_TOKEN));

// Start the server.
Deno.serve(
{ port: PORT, onListen },
makeHandler(kv),
);
}
if (import.meta.main) {
await main();
}

/**
* main is the entrypoint for the Shorter application command.
*/
export async function main() {
// Set up queue listener.
const kv = await Deno.openKv();
kv.listenQueue(makeTTLMessageListener(GITHUB_TOKEN));

// Start the server.
Deno.serve(
{ port: PORT, onListen },
makeHandler(kv),
);
}
No delivery. I’ll double check if it works locally.
Ccknight10/4/2023
I think you can also hoist all the main() code to top level, no need for await main, etc. Not sure that's your problem, but just a pointer. Anyway, I'd add console.log messages after kv.listenQueue to validate it was setup properly and also after kv.enqueue to validate the message was sent. Check your Deploy logs tab as well for any errors.
EEthanThatOneKid10/4/2023
Thanks for the pointers. I’ll start on a little repro repo to help clear up any hurdles for myself and anyone else who it may be of use to.
EEthanThatOneKid10/7/2023
After some experimenting, it’s possible to establish a Deno Queue in the top-level scope, in an abstracted main function, and with an in-memory kv instance, all with and without delays. Here are the manually-testable examples: https://github.com/EthanThatOneKid/deno_queues/tree/main/examples
GitHub
deno_queues/examples at main · EthanThatOneKid/deno_queues
🦕 Example usage of https://deno.com/blog/queues! Contribute to EthanThatOneKid/deno_queues development by creating an account on GitHub.
Iigorzi10/8/2023
@EthanThatOneKid (He/Him) - are you not able to get queue messages delivered on Deploy? Can you please DM me your Deploy project?
EEthanThatOneKid10/8/2023
Wow thank you for following up with me in DMs! At the time of opening this forum post something was fishy, but now all seems to be working as expected. For me, this forum post is resolved. cc @igorzi

Looking for more? Join the community!

Recommended Posts
Deno compile target errorHello, I am trying to compile a Deno api using `deno --unstable ./path/to/api/index.ts --output ./paHow to avoid the method POST to executed in the URL I am redirected to?How to avoid the method POST to executed in the URL I am redirected to? routes/admin/login.tsx ```thow to use Untar without deprecated functions?`Untar` from std/archives requires an instance of `Reader` - apparently most functions return some RHelp, does the middleware example in the Deno Fresh documentation not work for anyone else?I tried to follow the example in Deno Fresh about middlewares, but it doesn't work, the content `ctxDeno Cache locationHello, I am trying to cache my dependencies during the compile action using Github Actions, where doHow to build rusty_v8 with old v8 version?Hello all ! I am trying to build rusty_v8 (https://github.com/denoland/rusty_v8) with an old versionCan someone explain WebSocketStream to me?Whenever I try to connect using WebSocketStream and the host doesn't respond, my program inevitably deno doc: error: fp-tsthat's pretty much all I have :/ Running `deno doc Server.ts` only yields `error: fp-ts`. Can I enabI want to add my package xmlbuilder2 to deno.landBut somebody already added it, albeit with his own forked repository (now non-existent, thus unusablCache imports in deno.jsonIs there a way to cache imports defined in deno.json? I am hoping to avoid additional deps.ts file.typescript type definition for deno.jsonDoes it exist, and where can I get it?Publishing (and configuring) the webhook for deno.land from monorepoThanks in advance for your help! I went through the setup on https://deno.com/add_module for my jupLooking for a Dev who is well-versed in Fast-Delivery of building front-end pages using React.js forLooking for a Dev who is well-versed in Fast-Delivery of building front-end pages using React.js forHow to assert object with a field of a given type?Hi, I'm writing an integration test that needs to assert an object response, where the ID field can Deno + LitHey how can use the [Lit](https://lit.dev/) framework with Deno? Is there a guide or config on how tIssues with Crypto Subtle Digest ext:deno_crypto/00_crypto.jsCurrently we are using `deno_core v0.200.0` `deno_runtime v0.123.0` when attempting to invoke `cryptAnyway to use deno fmt within a script itself without having to call deno again?I am working on a code generator and I'd like to run a string through deno fmt before I save to fileinteraction_endpoint_url: couldn't be verifiedI'm trying to create an http interactions bot using deno deploy, but sometimes my url fails to be veLost access to deno land module, how to reset the repo?My repository was accidentally destroyed on GitHub and I recreated it the same exact way. The webhooBDD with async testsI'd like to run some tests that all call the same helper function that wraps the bdd `it` function.