//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);
}
});