From 53e5fd2576040510886c1fe94fc45bf2b730872d Mon Sep 17 00:00:00 2001 From: Lukas <69743171+quick007@users.noreply.github.com> Date: Wed, 13 Mar 2024 21:50:26 -0700 Subject: [PATCH] fix build issue --- .prettierrc | 2 +- deno.jsonc | 8 +- utils/email.ts | 194 ++++++++++++++++++++++++------------------------- 3 files changed, 102 insertions(+), 102 deletions(-) diff --git a/.prettierrc b/.prettierrc index 59aea2d..82b64e5 100644 --- a/.prettierrc +++ b/.prettierrc @@ -3,7 +3,7 @@ "jsxSingleQuote": false, "singleQuote": false, "trailingComma": "all", - "tabWidth": 4, + "tabWidth": 2, "endOfLine": "lf", "useTabs": true } diff --git a/deno.jsonc b/deno.jsonc index 32362ad..28e0ea8 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -3,10 +3,10 @@ "tasks": { "check": "deno fmt --check && deno lint && deno check **/*.ts && deno check **/*.tsx", "fmt": "deno fmt && npx prettier . --write", - "start": "deno run -A --unstable-kv --unstable-cron --watch=static/,routes/ dev.ts", - "build": "deno run -A --unstable-kv --unstable-cron dev.ts build", - "preview": "deno run --unstable-kv --unstable-cron -A main.ts", - "update": "deno run --unstable-kv --unstable-cron -A -r https://fresh.deno.dev/update ." + "start": "deno run -A --unstable-kv --watch=static/,routes/ dev.ts", + "build": "deno run -A --unstable-kv dev.ts build", + "preview": "deno run --unstable-kv -A main.ts", + "update": "deno run --unstable-kv -A -r https://fresh.deno.dev/update ." }, "lint": { "rules": { "tags": ["fresh", "recommended"], "include": ["no-unused-vars"] } diff --git a/utils/email.ts b/utils/email.ts index d998749..4f3529a 100644 --- a/utils/email.ts +++ b/utils/email.ts @@ -1,110 +1,110 @@ -import { kv, Event, Ticket, ShowTime } from "@/utils/db/kv.ts"; +// import { kv, Event, Ticket, ShowTime } from "@/utils/db/kv.ts"; -const cronTask = async () => { - const events = kv.list({ prefix: ["event"] }); +// const cronTask = async () => { +// const events = kv.list({ prefix: ["event"] }); - for await (const event of events) { - const showtimes = event.value.showTimes - .filter((s) => !s.hasEmailed) - .sort( - (a, b) => - new Date(a.startDate).valueOf() - - new Date(b.startDate).valueOf(), - ); +// for await (const event of events) { +// const showtimes = event.value.showTimes +// .filter((s) => !s.hasEmailed) +// .sort( +// (a, b) => +// new Date(a.startDate).valueOf() - +// new Date(b.startDate).valueOf(), +// ); - const showtimesStartingIn24Hours = showtimes.filter( - (showtime) => - new Date(showtime.startDate).valueOf() - Date.now() < - 24 * 60 * 60 * 1000, - ); +// const showtimesStartingIn24Hours = showtimes.filter( +// (showtime) => +// new Date(showtime.startDate).valueOf() - Date.now() < +// 24 * 60 * 60 * 1000, +// ); - if (showtimesStartingIn24Hours.length > 0) { - await kv.enqueue( - JSON.stringify({ - event, - showtimesStartingIn24Hours, - eventID: event.key[1], - }), - ); - } - } -}; +// if (showtimesStartingIn24Hours.length > 0) { +// await kv.enqueue( +// JSON.stringify({ +// event, +// showtimesStartingIn24Hours, +// eventID: event.key[1], +// }), +// ); +// } +// } +// }; -cronTask(); +// cronTask(); -// Deno.cron("check emails", "0 */4 * * *", cronTask); +// // Deno.cron("check emails", "0 */4 * * *", cronTask); -kv.listenQueue(async (msg) => { - const message = JSON.parse(msg) as - | { - eventID: string; - event: Event; - showtimesStartingIn24Hours: Event["showTimes"]; - } - | { - eventID: string; - event: Event; - showtime: ShowTime; - cursor: string; - }; +// kv.listenQueue(async (msg) => { +// const message = JSON.parse(msg) as +// | { +// eventID: string; +// event: Event; +// showtimesStartingIn24Hours: Event["showTimes"]; +// } +// | { +// eventID: string; +// event: Event; +// showtime: ShowTime; +// cursor: string; +// }; - if ("showtimesStartingIn24Hours" in message) { - let delay = 0; +// if ("showtimesStartingIn24Hours" in message) { +// let delay = 0; - for (const showtime of message.showtimesStartingIn24Hours) { - await kv.set(["event", message.eventID], { - ...message.event, - showTimes: message.event.showTimes.map((s) => - s.id === showtime.id ? { ...s, hasEmailed: true } : s, - ), - }); - await kv.enqueue( - JSON.stringify({ - eventID: message.eventID, - event: message.event, - showtime, - }), - { - delay: delay, - }, - ); +// for (const showtime of message.showtimesStartingIn24Hours) { +// await kv.set(["event", message.eventID], { +// ...message.event, +// showTimes: message.event.showTimes.map((s) => +// s.id === showtime.id ? { ...s, hasEmailed: true } : s, +// ), +// }); +// await kv.enqueue( +// JSON.stringify({ +// eventID: message.eventID, +// event: message.event, +// showtime, +// }), +// { +// delay: delay, +// }, +// ); - delay += 1000 + Math.random() * 3000; - } - } else { - await startEmails( - message.eventID, - message.event, - message.showtime, - message.cursor, - ); - } -}); +// delay += 1000 + Math.random() * 3000; +// } +// } else { +// await startEmails( +// message.eventID, +// message.event, +// message.showtime, +// message.cursor, +// ); +// } +// }); -const startEmails = async ( - eventID: string, - event: Event, - showtime: ShowTime, - cursor?: string, -) => { - const tickets = kv.list( - { prefix: ["ticket", eventID, showtime.id] }, - { cursor, limit: 18 }, - ); +// const startEmails = async ( +// eventID: string, +// event: Event, +// showtime: ShowTime, +// cursor?: string, +// ) => { +// const tickets = kv.list( +// { prefix: ["ticket", eventID, showtime.id] }, +// { cursor, limit: 18 }, +// ); - for await (const ticket of tickets) { - console.log("Sending email to", ticket.value.userEmail); - } +// for await (const ticket of tickets) { +// console.log("Sending email to", ticket.value.userEmail); +// } - if (tickets.cursor) { - await kv.enqueue( - JSON.stringify({ - eventID, - event, - showtime, - cursor: tickets.cursor, - }), - { delay: 1000 }, - ); - } -}; +// if (tickets.cursor) { +// await kv.enqueue( +// JSON.stringify({ +// eventID, +// event, +// showtime, +// cursor: tickets.cursor, +// }), +// { delay: 1000 }, +// ); +// } +// };