|
1 | 1 | import cron from "node-cron"; |
2 | | -import expireAdminNotes from "./scripts/expireAdminNotes"; |
3 | | -import expireAdminAnnouncements from "./scripts/expireAdminAnnouncements"; |
4 | | -import expireLoginStreak from "./scripts/expireLoginStreak"; |
5 | | -import createAssignedTasks from "./scripts/createAssignedTask"; |
6 | | -import { |
7 | | - sendWeeklyReports, |
8 | | - sendMonthlyReports, |
9 | | -} from "./scripts/sendReportEmails"; |
| 2 | +import { isLastDayOfMonth } from "date-fns"; |
| 3 | +import expireNotes from "./scripts/expireNotes"; |
| 4 | +import expireAnnouncements from "./scripts/expireAnnouncements"; |
| 5 | +import resetLoginStreak from "./scripts/resetLoginStreak"; |
| 6 | +import assignRequiredTasks from "./scripts/assignRequiredTasks"; |
| 7 | +import sendMonthlyReport from "./scripts/sendMonthlyReport"; |
| 8 | +import sendWeeklyReport from "./scripts/sendWeeklyReport"; |
10 | 9 |
|
11 | 10 | cron.schedule("0 0 * * * *", async () => { |
12 | | - const res = await expireAdminNotes(); |
13 | | - if (res) { |
14 | | - console.log("Deleted expired notes"); |
15 | | - } else { |
16 | | - console.log("Could not expire admin notes"); |
17 | | - } |
| 11 | + await expireNotes(); |
18 | 12 | }); |
19 | 13 |
|
20 | 14 | cron.schedule("0 0 0 * * *", async () => { |
21 | | - const res = await expireAdminAnnouncements(); |
22 | | - if (res) { |
23 | | - console.log("Expired admin announcements"); |
24 | | - } else { |
25 | | - console.log("Could not expire admin announcements"); |
26 | | - } |
| 15 | + await expireAnnouncements(); |
27 | 16 | }); |
28 | 17 |
|
29 | | -cron.schedule("0 0 0 * * *", async () => { |
30 | | - const res = await expireLoginStreak(); |
31 | | - if (res) { |
32 | | - console.log("Expired login streaks"); |
33 | | - } else { |
34 | | - console.log("Could not expire login streaks"); |
35 | | - } |
| 18 | +cron.schedule("0 59 23 * * *", async () => { |
| 19 | + await resetLoginStreak(); |
36 | 20 | }); |
37 | 21 |
|
38 | | -cron.schedule("0 0 * * 1", async () => { |
39 | | - const res = await createAssignedTasks(); |
40 | | - if (res) { |
41 | | - console.log("Created assigned tasks"); |
42 | | - } else { |
43 | | - console.log("Could not create assigned tasks"); |
44 | | - } |
| 22 | +cron.schedule("0 0 0 * * 0", async () => { |
| 23 | + await assignRequiredTasks(); |
45 | 24 | }); |
46 | 25 |
|
47 | | -// Weekly reports - every Monday at 9 AM |
48 | | -cron.schedule("0 9 * * 1", async () => { |
49 | | - const timestamp = new Date().toISOString(); |
50 | | - console.log( |
51 | | - `[${timestamp}] Starting weekly report generation and emailing...` |
52 | | - ); |
53 | | - |
54 | | - const res = await sendWeeklyReports(); |
55 | | - if (res) { |
56 | | - console.log(`[${timestamp}] Weekly reports sent successfully`); |
57 | | - } else { |
58 | | - console.log(`[${timestamp}] Could not send weekly reports`); |
59 | | - } |
| 26 | +cron.schedule("0 0 23 * * 6", async () => { |
| 27 | + await sendWeeklyReport(); |
60 | 28 | }); |
61 | 29 |
|
62 | | -// Monthly reports - first day of month at 9 AM |
63 | | -cron.schedule("0 9 1 * *", async () => { |
64 | | - const timestamp = new Date().toISOString(); |
65 | | - console.log( |
66 | | - `[${timestamp}] Starting monthly report generation and emailing...` |
67 | | - ); |
68 | | - |
69 | | - const res = await sendMonthlyReports(); |
70 | | - if (res) { |
71 | | - console.log(`[${timestamp}] Monthly reports sent successfully`); |
72 | | - } else { |
73 | | - console.log(`[${timestamp}] Could not send monthly reports`); |
| 30 | +cron.schedule("0 0 23 * * *", async () => { |
| 31 | + if (isLastDayOfMonth(new Date())) { |
| 32 | + await sendMonthlyReport(); |
74 | 33 | } |
75 | 34 | }); |
0 commit comments