refactor: use env variables and update project structure
This commit is contained in:
35
apps/worker/main.ts
Normal file
35
apps/worker/main.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { Redis } from 'ioredis';
|
||||
import { spawn } from 'child_process';
|
||||
import dotenv from 'dotenv';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const REDIS_URL = process.env.REDIS_URL || 'redis://localhost:6379';
|
||||
const CONTAINER_NAME = process.env.MAILCOW_CONTAINER_NAME || 'mailcowdockerized-dovecot-mailcow-1';
|
||||
|
||||
const redis = new Redis(REDIS_URL);
|
||||
|
||||
console.log("🚀 AyrisTech Worker Bağlanıyor...");
|
||||
|
||||
// Dovecot loglarını dinliyoruz
|
||||
const logProcess = spawn('docker', ['logs', '-f', CONTAINER_NAME]);
|
||||
|
||||
logProcess.stdout.on('data', async (data) => {
|
||||
const line = data.toString();
|
||||
|
||||
// Mailcow'un mail teslimat logunu yakala
|
||||
if (line.includes('saved mail to INBOX')) {
|
||||
const match = line.match(/user=<([^>]+)>/);
|
||||
if (match) {
|
||||
const email = match[1];
|
||||
console.log(`📩 Mail Geldi: ${email}`);
|
||||
|
||||
// Olayı Redis'e fırlat (Pub/Sub)
|
||||
// Bu sayede Next.js veya diğer servisler bu haberi alabilir
|
||||
await redis.publish('NEW_MAIL_EVENT', JSON.stringify({
|
||||
to: email,
|
||||
time: new Date().toISOString()
|
||||
}));
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user