mirror of
https://github.com/complexcaresolutions/telegram-media-bot.git
synced 2026-03-17 13:53:41 +00:00
feat: add entry point with graceful shutdown and PM2 config
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
6a6710c666
commit
412175030a
2 changed files with 59 additions and 0 deletions
17
ecosystem.config.cjs
Normal file
17
ecosystem.config.cjs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
module.exports = {
|
||||
apps: [{
|
||||
name: 'telegram-media-bot',
|
||||
script: './dist/index.js',
|
||||
instances: 1,
|
||||
autorestart: true,
|
||||
watch: false,
|
||||
max_memory_restart: '256M',
|
||||
env: {
|
||||
NODE_ENV: 'production',
|
||||
},
|
||||
error_file: './logs/error.log',
|
||||
out_file: './logs/out.log',
|
||||
merge_logs: true,
|
||||
time: true,
|
||||
}],
|
||||
};
|
||||
42
src/index.ts
Normal file
42
src/index.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import { config } from './config.js';
|
||||
import { createLogger, setLogLevel } from './utils/logger.js';
|
||||
import { createBot } from './bot.js';
|
||||
import { registerHandlers } from './telegram/handlers.js';
|
||||
|
||||
const log = createLogger('Main');
|
||||
|
||||
setLogLevel(config.logLevel as 'debug' | 'info' | 'warn' | 'error');
|
||||
|
||||
async function main(): Promise<void> {
|
||||
log.info('Starting Telegram Media Upload Bot...');
|
||||
log.info(`Environment: ${config.nodeEnv}`);
|
||||
log.info(`Payload API: ${config.payload.apiUrl}`);
|
||||
log.info(`Default Tenant: ${config.defaultTenantId}`);
|
||||
log.info(`Allowed Users: ${config.telegram.allowedUserIds.join(', ')}`);
|
||||
|
||||
const bot = createBot();
|
||||
registerHandlers(bot);
|
||||
|
||||
// Graceful shutdown
|
||||
const shutdown = async (signal: string) => {
|
||||
log.info(`Received ${signal}, shutting down...`);
|
||||
bot.stop();
|
||||
setTimeout(() => {
|
||||
log.warn('Forced shutdown after timeout');
|
||||
process.exit(1);
|
||||
}, 60_000);
|
||||
};
|
||||
|
||||
process.on('SIGINT', () => shutdown('SIGINT'));
|
||||
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
||||
|
||||
// Start bot
|
||||
await bot.start({
|
||||
onStart: () => log.info('Bot is running! Listening for messages...'),
|
||||
});
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
log.error('Fatal error', error);
|
||||
process.exit(1);
|
||||
});
|
||||
Loading…
Reference in a new issue