tigawana
tigawana7mo ago

deno deploy queues

is there a special flag or setting required for queues in deno deploy , i ceated a very simple example that works locally but not on deploy
app.get('/test', async(c) => {
try {
const env = await load();
const db = await Deno.openKv();

db.listenQueue(async(msg) => {
const data = msg as { channel: string; text: string };
console.log("=== QUEUE MESSAGE === ",data);
await db.set(["test-queues", data.channel], data.text);
});

await db.enqueue({ channel: "C123456", text: "Slack message" }, {
delay: 0,
});
return c.json({
env,
})
} catch (error) {
return c.text("error with queues === "+error.message, 401);
}
})
app.get('/test', async(c) => {
try {
const env = await load();
const db = await Deno.openKv();

db.listenQueue(async(msg) => {
const data = msg as { channel: string; text: string };
console.log("=== QUEUE MESSAGE === ",data);
await db.set(["test-queues", data.channel], data.text);
});

await db.enqueue({ channel: "C123456", text: "Slack message" }, {
delay: 0,
});
return c.json({
env,
})
} catch (error) {
return c.text("error with queues === "+error.message, 401);
}
})
2 Replies
cknight
cknight7mo ago
The docs could do with updating but the db.listenQueue must be declared at the top level of your module on Deploy for it to work.
tigawana
tigawana7mo ago
ohh, something like this ?
const db = await Deno.openKv();
db.listenQueue(async (msg) => {
const data = msg as { channel: string; text: string };
console.log("=== QUEUE MESSAGE === ", data);
await db.set(["test-queues", data.channel], data.text);
console.log("saved to kv ==== ",await db.get(["test-queues", data.channel]));
});

app.get('/test', async(c) => {
try {
const env = await load();
// const db = await Deno.openKv();

// db.listenQueue(async(msg) => {
// const data = msg as { channel: string; text: string };
// console.log("=== QUEUE MESSAGE === ",data);
// await db.set(["test-queues", data.channel], data.text);
// });

await db.enqueue({ channel: "C123456", text: "Slack message" }, {
delay: 0,
});
return c.json({
env,
})
} catch (error) {
return c.text("error with queues === "+error.message, 401);
}
})
const db = await Deno.openKv();
db.listenQueue(async (msg) => {
const data = msg as { channel: string; text: string };
console.log("=== QUEUE MESSAGE === ", data);
await db.set(["test-queues", data.channel], data.text);
console.log("saved to kv ==== ",await db.get(["test-queues", data.channel]));
});

app.get('/test', async(c) => {
try {
const env = await load();
// const db = await Deno.openKv();

// db.listenQueue(async(msg) => {
// const data = msg as { channel: string; text: string };
// console.log("=== QUEUE MESSAGE === ",data);
// await db.set(["test-queues", data.channel], data.text);
// });

await db.enqueue({ channel: "C123456", text: "Slack message" }, {
delay: 0,
});
return c.json({
env,
})
} catch (error) {
return c.text("error with queues === "+error.message, 401);
}
})
this too isn.t working , only locally , am i doing it wrong?