Pinolero
Pinolero13mo ago

Is there a way to reset/flush my deno vk queues on deploy?

Nothing seems to be queuing. I would like to reset it if possible?
13 Replies
fro.profesional
fro.profesional13mo ago
Leave and empty handler maybe?
Pinolero
PinoleroOP13mo ago
kv.listenQueue(async (msg: any) => {} ); like so? i'll give it a try
cknight
cknight13mo ago
You mention nothing seems to be queuing. What do you mean by this?
Pinolero
PinoleroOP13mo ago
I've enqueue items, but with a delay of 100ms - but the items don't seem to execute. Not even console logging the error if any. Note, I was working around in my local environment - testing queues and such. Eventually in my local environment, it stopped working. (simply delaying messages to log to console). Then I made some adjustments, deployed to deno deploy - and started testing out my queues in live environment. Now, it stopped working. I'm not sure if my local changes kv queues changes deployed to deno deploy and got it stuck?
cknight
cknight13mo ago
Can you share enqueue and listenQueue code?
Pinolero
PinoleroOP13mo ago
//routes/api/emailer
const QueueAccountForEmailing = async (items: any, emailType: string) => {
const rowIds = items;
//console.log(`queuing row ids: ${rowIds}`);
console.log(`size of rowIds: ${rowIds.length}`);
for (const id of rowIds) {
await kv.enqueue(
{ type: "emailer", id: id, emailType }, { delay: 100 }
);
}
}


export const handler = {
async POST(_req:any) {
const payload = (await _req.json());
await QueueAccountForEmailing(payload.items, payload.emailType);
return new Response();
}
};

//queues.ts
import { kv } from "./kv.ts";
import { ExecuteWebhook } from "../routes/api/renewalupdate.ts";
import { CheckifEmailSentAndSendMail } from "../routes/api/emailer.ts";
import { GetAccountScrape } from "../routes/api/scraper.ts";

kv.listenQueue(async (msg: any) => {
if (msg.type === "emailer") {
await CheckifEmailSentAndSendMail(msg.id, msg.emailType);
}
if (msg.type === "scraper") {
await GetAccountScrape(msg.id);
}
if (msg.type === "update") {
await ExecuteWebhook(msg.id);
}
});
//routes/api/emailer
const QueueAccountForEmailing = async (items: any, emailType: string) => {
const rowIds = items;
//console.log(`queuing row ids: ${rowIds}`);
console.log(`size of rowIds: ${rowIds.length}`);
for (const id of rowIds) {
await kv.enqueue(
{ type: "emailer", id: id, emailType }, { delay: 100 }
);
}
}


export const handler = {
async POST(_req:any) {
const payload = (await _req.json());
await QueueAccountForEmailing(payload.items, payload.emailType);
return new Response();
}
};

//queues.ts
import { kv } from "./kv.ts";
import { ExecuteWebhook } from "../routes/api/renewalupdate.ts";
import { CheckifEmailSentAndSendMail } from "../routes/api/emailer.ts";
import { GetAccountScrape } from "../routes/api/scraper.ts";

kv.listenQueue(async (msg: any) => {
if (msg.type === "emailer") {
await CheckifEmailSentAndSendMail(msg.id, msg.emailType);
}
if (msg.type === "scraper") {
await GetAccountScrape(msg.id);
}
if (msg.type === "update") {
await ExecuteWebhook(msg.id);
}
});
running this using deno fresh in deno deploy, in the analytics section - it does show as writes occuring. I just don't know why it isn't running. My delay is only 100ms I'm only using kv for the queues, so there are no other writes anywhere. And btw, I am not sending mail from deno deploy. It's just pointing to an aws endpoint that connects to my business exchange account.
cknight
cknight13mo ago
Is queues.ts imported anywhere?
Pinolero
PinoleroOP13mo ago
no it isn't
cknight
cknight13mo ago
Ah, then it can't be discovered and registered
Pinolero
PinoleroOP13mo ago
thas crazy though .. its been like this for 3 days. It was never imported anywhere and it was running!
cknight
cknight13mo ago
For simplicity, try copying that queues.ts code into your fresh main.ts file
Pinolero
PinoleroOP13mo ago
okay, i'll try that hello, thanks, that seemed to do the trick! thanks a lot I appreciate it. But no shit... I swear I had my listenQueue in another file, NOT being imported at all. It was working.... on local and deploy. I appreciate the support 🙏
cknight
cknight13mo ago
Excellent! Great to hear it's working now. I suspect you might also be able to import queues.ts I think, but I kind of prefer the explicit declaration in main.ts. You could always shift the logic of the listener to another module.