backend/config/cron-tasks.ts (view raw)
1import { DateTime } from "luxon";
2import pMap from "p-map";
3
4export default {
5 /**
6 * Send event recap to creators
7 * Everyday at 08:00
8 */
9 "0 8 * * *": async ({ strapi }) => {
10 const events = await strapi.entityService.findMany("api::event.event", {
11 filters: {
12 date: {
13 $gte: DateTime.now().toISODate(),
14 },
15 },
16 limit: -1,
17 });
18
19 await pMap(events, strapi.service("api::event.event").sendDailyRecap, {
20 concurrency: 5,
21 });
22 },
23 /**
24 * Send event recap when it has ended
25 * Only to events with a provided 'date' field
26 * Everyday at 08:30
27 */
28 "30 8 * * *": async ({ strapi }) => {
29 const events = await strapi.entityService.findMany("api::event.event", {
30 filters: {
31 date: {
32 $eq: DateTime.now().minus({ day: 1 }).toISODate(),
33 },
34 },
35 populate: ["travels", "passengers", "passengers.travel"],
36 limit: -1,
37 });
38 await pMap(events, strapi.service("api::event.event").sendEndRecap, {
39 concurrency: 5,
40 });
41 },
42};