-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
66 lines (56 loc) · 2.35 KB
/
index.ts
File metadata and controls
66 lines (56 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// index.ts
import { bot } from './src/bot/instance'
import { startBot } from './src/bot/start'
import { closeDb } from './src/db'
import { startApiServer } from './src/api/server'
const BUILD_TIME = new Date().toLocaleString('en-GB', {
timeZone: 'Europe/Helsinki',
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false
})
/**
* Main entry point
*/
async function main(): Promise<void> {
try {
// Start the bot
await startBot()
// Start API Server
const API_PORT = parseInt(process.env.API_PORT || '3000')
console.log(`🌐 Starting API server on port ${API_PORT}...`)
startApiServer(API_PORT)
console.log('✅ API server started\n')
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━')
console.log('✅ All services running')
console.log(`📅 Build: ${BUILD_TIME}`)
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n')
// Graceful shutdown handlers
const shutdown = async (signal: string): Promise<void> => {
console.log('\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━')
console.log(`🛑 ${signal} received, shutting down gracefully...`)
// Stop the bot
bot.stop(signal)
console.log('✅ Bot stopped')
// Close database connections
await closeDb()
console.log('✅ Database closed')
console.log('👋 Shutdown complete')
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n')
process.exit(0)
}
process.once('SIGINT', () => shutdown('SIGINT'))
process.once('SIGTERM', () => shutdown('SIGTERM'))
} catch (error) {
console.error('\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━')
console.error('❌ Failed to start application:', error)
console.error('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n')
await closeDb()
process.exit(1)
}
}
main()