feat: scaffold NestJS BullMQ worker skeleton
This commit is contained in:
parent
41f4173667
commit
eaa8e8638f
10 changed files with 125 additions and 0 deletions
2
.env.example
Normal file
2
.env.example
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
# Redis (ceo-os-redis, Coolify)
|
||||||
|
REDIS_URL=redis://default:CHANGE_ME@ceo-os-redis:6379/0
|
||||||
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
node_modules/
|
||||||
|
dist/
|
||||||
|
.env
|
||||||
|
*.log
|
||||||
14
Dockerfile
Normal file
14
Dockerfile
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
FROM node:22-alpine AS build
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package.json ./
|
||||||
|
RUN npm install
|
||||||
|
COPY . .
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
FROM node:22-alpine
|
||||||
|
WORKDIR /app
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
COPY --from=build /app/node_modules ./node_modules
|
||||||
|
COPY --from=build /app/dist ./dist
|
||||||
|
COPY package.json ./
|
||||||
|
CMD ["node", "dist/main"]
|
||||||
11
README.md
11
README.md
|
|
@ -1,2 +1,13 @@
|
||||||
# ceo-worker
|
# ceo-worker
|
||||||
|
|
||||||
|
Worker de background pentru CEO-OS, bazat pe BullMQ (NestJS). Consuma joburi din coada Redis (`ceo-os-redis`, Coolify).
|
||||||
|
|
||||||
|
## Dezvoltare
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install
|
||||||
|
cp .env.example .env
|
||||||
|
npm run start:dev
|
||||||
|
```
|
||||||
|
|
||||||
|
Contine un procesor placeholder (`example` queue) — inlocuieste-l cu joburile reale (rapoarte, notificari, sincronizari).
|
||||||
|
|
|
||||||
5
nest-cli.json
Normal file
5
nest-cli.json
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://json.schemastore.org/nest-cli",
|
||||||
|
"collection": "@nestjs/schematics",
|
||||||
|
"sourceRoot": "src"
|
||||||
|
}
|
||||||
29
package.json
Normal file
29
package.json
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
{
|
||||||
|
"name": "ceo-worker",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"description": "CEO-OS background worker (BullMQ)",
|
||||||
|
"private": true,
|
||||||
|
"license": "UNLICENSED",
|
||||||
|
"scripts": {
|
||||||
|
"build": "nest build",
|
||||||
|
"start": "node dist/main",
|
||||||
|
"start:dev": "nest start --watch",
|
||||||
|
"lint": "eslint \"src/**/*.ts\"",
|
||||||
|
"test": "jest"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@nestjs/bullmq": "^11.0.0",
|
||||||
|
"@nestjs/common": "^11.0.0",
|
||||||
|
"@nestjs/config": "^4.0.0",
|
||||||
|
"@nestjs/core": "^11.0.0",
|
||||||
|
"@nestjs/platform-express": "^11.0.0",
|
||||||
|
"bullmq": "^5.28.0",
|
||||||
|
"reflect-metadata": "^0.2.2",
|
||||||
|
"rxjs": "^7.8.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@nestjs/cli": "^11.0.0",
|
||||||
|
"@types/node": "^22.0.0",
|
||||||
|
"typescript": "^5.6.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
18
src/app.module.ts
Normal file
18
src/app.module.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { ConfigModule } from '@nestjs/config';
|
||||||
|
import { BullModule } from '@nestjs/bullmq';
|
||||||
|
import { ExampleProcessor } from './queue/example.processor';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [
|
||||||
|
ConfigModule.forRoot({ isGlobal: true }),
|
||||||
|
BullModule.forRoot({
|
||||||
|
connection: {
|
||||||
|
url: process.env.REDIS_URL,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
BullModule.registerQueue({ name: 'example' }),
|
||||||
|
],
|
||||||
|
providers: [ExampleProcessor],
|
||||||
|
})
|
||||||
|
export class AppModule {}
|
||||||
12
src/main.ts
Normal file
12
src/main.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
import 'reflect-metadata';
|
||||||
|
import { NestFactory } from '@nestjs/core';
|
||||||
|
import { AppModule } from './app.module';
|
||||||
|
|
||||||
|
async function bootstrap() {
|
||||||
|
const app = await NestFactory.createApplicationContext(AppModule);
|
||||||
|
await app.init();
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('ceo-worker started, listening for BullMQ jobs');
|
||||||
|
}
|
||||||
|
|
||||||
|
bootstrap();
|
||||||
10
src/queue/example.processor.ts
Normal file
10
src/queue/example.processor.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
import { Processor, WorkerHost } from '@nestjs/bullmq';
|
||||||
|
import { Job } from 'bullmq';
|
||||||
|
|
||||||
|
@Processor('example')
|
||||||
|
export class ExampleProcessor extends WorkerHost {
|
||||||
|
async process(job: Job): Promise<void> {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(`processing job ${job.id}`, job.data);
|
||||||
|
}
|
||||||
|
}
|
||||||
20
tsconfig.json
Normal file
20
tsconfig.json
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "commonjs",
|
||||||
|
"target": "ES2022",
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"declaration": false,
|
||||||
|
"removeComments": true,
|
||||||
|
"emitDecoratorMetadata": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"sourceMap": true,
|
||||||
|
"outDir": "./dist",
|
||||||
|
"baseUrl": "./",
|
||||||
|
"incremental": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"strict": true,
|
||||||
|
"strictNullChecks": true,
|
||||||
|
"noImplicitAny": true,
|
||||||
|
"esModuleInterop": true
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue