feat: add production deployment and runtime safeguards
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
8ce2fcdfea
commit
a9ef4d776d
+22
-7
@@ -1,4 +1,10 @@
|
||||
import { loadDotEnv, APP_PORT, paths } from '../src/env.mjs';
|
||||
import { loadDotEnv, APP_HOST, APP_PORT, paths, telegramConfig } from '../src/env.mjs';
|
||||
import { createTelegramAlerter } from '../src/alerts/telegram.mjs';
|
||||
import {
|
||||
hasCampaignsPausedByRestart,
|
||||
notifyStartupState,
|
||||
startInitialWhatsAppReconnect
|
||||
} from '../src/alerts/runtime-alerts.mjs';
|
||||
import { openDb, ensureSeeds, recoverPendingOutreach, updateOutreachMessageStatus } from '../src/db.mjs';
|
||||
import { createJobManager, recoverOrphans } from '../src/jobs/manager.mjs';
|
||||
import { createAppServer } from '../src/server/index.mjs';
|
||||
@@ -18,8 +24,12 @@ await ensureSeeds(db, { log });
|
||||
recoverOrphans(db, log);
|
||||
recoverPendingOutreach(db);
|
||||
pauseCampaignsAfterRestart(db);
|
||||
const campaignsPausedByRestart = hasCampaignsPausedByRestart(db);
|
||||
recoverReservedCampaignQueue(db);
|
||||
|
||||
const tg = telegramConfig();
|
||||
const alerter = createTelegramAlerter({ enabled: tg.enabled, token: tg.botToken, chatId: tg.chatId, log });
|
||||
|
||||
const jobs = createJobManager({ db });
|
||||
const whatsapp = createWhatsAppManager({
|
||||
authDir: paths.whatsappAuth,
|
||||
@@ -27,16 +37,21 @@ const whatsapp = createWhatsAppManager({
|
||||
onMessageStatus: (event) => updateOutreachMessageStatus(db, event),
|
||||
onInboundMessage: (event) => recordInboundReply(db, event)
|
||||
});
|
||||
if (await hasWhatsAppSession(paths.whatsappAuth)) {
|
||||
whatsapp.connect().catch((error) => log(`whatsapp: reconexao inicial falhou: ${error.message}`));
|
||||
}
|
||||
void notifyStartupState({ alerter, whatsappStatus: whatsapp.getStatus().state, campaignsPausedByRestart, log });
|
||||
await startInitialWhatsAppReconnect({
|
||||
hasSession: () => hasWhatsAppSession(paths.whatsappAuth),
|
||||
whatsapp,
|
||||
alerter,
|
||||
log
|
||||
});
|
||||
const server = createAppServer({ db, jobs, whatsapp, log });
|
||||
const stopScheduler = startOutreachScheduler({ db, whatsapp, log });
|
||||
|
||||
const port = APP_PORT;
|
||||
server.listen(port, '127.0.0.1', () => {
|
||||
log(`Maquina Comercial Pessoal rodando em http://127.0.0.1:${port}`);
|
||||
log('somente este computador tem acesso (127.0.0.1). Ctrl+C para encerrar.');
|
||||
server.listen(port, APP_HOST, () => {
|
||||
log(`Maquina Comercial Pessoal rodando em http://${APP_HOST}:${port}`);
|
||||
if (APP_HOST === '127.0.0.1') log('somente este computador tem acesso (127.0.0.1). Ctrl+C para encerrar.');
|
||||
else log('modo container/rede: proteja o acesso com proxy HTTPS e senha forte.');
|
||||
});
|
||||
|
||||
let shuttingDown = false;
|
||||
|
||||
Reference in New Issue
Block a user