-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
54 lines (43 loc) · 1.25 KB
/
main.go
File metadata and controls
54 lines (43 loc) · 1.25 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
package main
import (
"context"
"log"
"os"
"os/signal"
"syscall"
"time"
)
func main() {
// Load configuration from environment variables
cfg, err := LoadConfig()
if err != nil {
log.Fatalf("failed to load configuration: %v", err)
}
// Create a new VM manager
vmManager, err := NewVMManager(cfg)
if err != nil {
log.Fatalf("failed to create VM manager: %v", err)
}
defer vmManager.Close()
// Initialize database tables
if err := vmManager.InitDatabase(); err != nil {
log.Fatalf("failed to initialize database: %v", err)
}
// Setup NATS subscriptions
if err := vmManager.SetupNATSSubscriptions(); err != nil {
log.Fatalf("failed to set up NATS subscriptions: %v", err)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Start the background VM expiration checker
vmManager.StartExpirationChecker(ctx, 1*time.Minute)
// Start the background cooldown expiration checker
vmManager.StartCooldownExpirationChecker(ctx, 1*time.Minute)
log.Println("VM manager service started and listening for NATS messages...")
// Wait for termination signal
done := make(chan os.Signal, 1)
signal.Notify(done, syscall.SIGINT, syscall.SIGTERM)
// Block until a signal is received
<-done
log.Println("shutting down...")
}