api: rig insights cron'ed workers
Parents:
c4e059e1 file(s) changed
- api/src/createApp.ts +24 -16
api/src/createApp.ts
1 -
import express from 'express';
2 -
import cors from 'cors';
3 -
import bodyParser from 'body-parser';
4 -
import morgan from 'morgan';
5 -
import mainRouter from '@app/routes/main';
6 -
import userRouter from '@app/routes/users';
7 -
import authRouter from '@app/routes/auth';
8 -
import moodRouter from '@app/routes/moods';
9 -
import triggerRouter from '@app/routes/triggers';
10 -
import sleepRecordRouter from '@app/routes/sleepRecords';
11 -
import { errorHandler } from '@app/middleware/errorHandler';
12 -
import { PrismaClient } from '@prisma/client';
13 -
import { bootWorkers, closeAllWorkers, closeAllQueues } from '@app/lib/queue';
14 -
import pino from 'pino';
15 -
import pinoHttp from 'pino-http';
16 -
import path from 'path';
1 +
import express from "express";
2 +
import cors from "cors";
3 +
import bodyParser from "body-parser";
4 +
import morgan from "morgan";
5 +
import mainRouter from "@app/routes/main";
6 +
import userRouter from "@app/routes/users";
7 +
import authRouter from "@app/routes/auth";
8 +
import moodRouter from "@app/routes/moods";
9 +
import triggerRouter from "@app/routes/triggers";
10 +
import sleepRecordRouter from "@app/routes/sleepRecords";
11 +
import insightRouter from "@app/routes/insights";
12 +
import { errorHandler } from "@app/middleware/errorHandler";
13 +
import { PrismaClient } from "@prisma/client";
14 +
import {
15 +
bootWorkers,
16 +
closeAllWorkers,
17 +
closeAllQueues,
18 +
scheduleInsights,
19 +
} from "@app/lib/queue";
20 +
21 +
import pino from "pino";
22 +
import pinoHttp from "pino-http";
23 +
import path from "path";
17 24
18 25
export function createApp() {
19 26
const app = express();
20 27
bootWorkers();
28 +
scheduleInsights();
21 29
22 30
// Configure CORS
23 31
app.use(cors({
24 32
origin: process.env.FRONTEND_URL || '*',
25 33
credentials: true
▸ 41 unchanged lines
67 75
68 76
const shutdown = async () => {
69 77
await Promise.all([closeAllWorkers(), closeAllQueues()]);
70 78
process.exit(0);
71 79
};