Skip to content

Commit

Permalink
fix build issue
Browse files Browse the repository at this point in the history
  • Loading branch information
quick007 committed Mar 14, 2024
1 parent aeb10e5 commit 53e5fd2
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"jsxSingleQuote": false,
"singleQuote": false,
"trailingComma": "all",
"tabWidth": 4,
"tabWidth": 2,
"endOfLine": "lf",
"useTabs": true
}
8 changes: 4 additions & 4 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
194 changes: 97 additions & 97 deletions utils/email.ts
Original file line number Diff line number Diff line change
@@ -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<Event>({ prefix: ["event"] });
// const cronTask = async () => {
// const events = kv.list<Event>({ 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<Ticket>(
{ prefix: ["ticket", eventID, showtime.id] },
{ cursor, limit: 18 },
);
// const startEmails = async (
// eventID: string,
// event: Event,
// showtime: ShowTime,
// cursor?: string,
// ) => {
// const tickets = kv.list<Ticket>(
// { 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 },
// );
// }
// };

0 comments on commit 53e5fd2

Please sign in to comment.