Initial commit: SDI SaaS Platform foundation
- Complete monorepo structure with pnpm workspaces - Prisma database schema with 20+ entities - NestJS API with 9 core modules - BullMQ orchestration worker - AWS and Azure provider adapters - Docker Compose infrastructure - Complete documentation
This commit is contained in:
62
apps/worker/src/main.ts
Normal file
62
apps/worker/src/main.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { Worker, Queue } from 'bullmq';
|
||||
import { PrismaClient } from '@sdi/database';
|
||||
import { ProvisioningOrchestrator } from './orchestration/provisioning-orchestrator';
|
||||
import Redis from 'ioredis';
|
||||
|
||||
const connection = new Redis(process.env.REDIS_URL || 'redis://localhost:6379', {
|
||||
maxRetriesPerRequest: null,
|
||||
});
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
const orchestrator = new ProvisioningOrchestrator(prisma);
|
||||
|
||||
// Provisioning queue worker
|
||||
const provisioningWorker = new Worker(
|
||||
'provisioning',
|
||||
async (job) => {
|
||||
console.log(`Processing job ${job.id}: ${job.name}`);
|
||||
|
||||
switch (job.name) {
|
||||
case 'provision-order':
|
||||
await orchestrator.provisionOrder(job.data.orderId);
|
||||
break;
|
||||
case 'modify-service':
|
||||
await orchestrator.modifyService(job.data.serviceId, job.data.changes);
|
||||
break;
|
||||
case 'suspend-service':
|
||||
await orchestrator.suspendService(job.data.serviceId);
|
||||
break;
|
||||
case 'terminate-service':
|
||||
await orchestrator.terminateService(job.data.serviceId);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unknown job type: ${job.name}`);
|
||||
}
|
||||
},
|
||||
{
|
||||
connection,
|
||||
concurrency: 5,
|
||||
limiter: {
|
||||
max: 10,
|
||||
duration: 1000,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
provisioningWorker.on('completed', (job) => {
|
||||
console.log(`✓ Job ${job.id} completed successfully`);
|
||||
});
|
||||
|
||||
provisioningWorker.on('failed', (job, err) => {
|
||||
console.error(`✗ Job ${job?.id} failed:`, err.message);
|
||||
});
|
||||
|
||||
// Graceful shutdown
|
||||
process.on('SIGTERM', async () => {
|
||||
console.log('SIGTERM received, closing worker...');
|
||||
await provisioningWorker.close();
|
||||
await prisma.$disconnect();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
console.log('🔧 Worker started and listening for jobs...');
|
||||
Reference in New Issue
Block a user