Skip to content

Commit 8b0b9d3

Browse files
Alec CunninghamAlec Cunningham
Alec Cunningham
authored and
Alec Cunningham
committed
feat: add graceful termination
1 parent 4d73151 commit 8b0b9d3

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

cmd/server/main.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"log"
55
"os"
66
"os/exec"
7+
"os/signal"
8+
"syscall"
79

810
"github.com/moosh3/github-actions-aggregator/pkg/api"
911
"github.com/moosh3/github-actions-aggregator/pkg/config"
@@ -36,9 +38,22 @@ func main() {
3638
githubClient := github.NewClient(cfg.GitHub.AccessToken)
3739

3840
workerPool := worker.NewWorkerPool(database, cfg.WorkerPoolSize)
41+
workerPool.Start()
3942

4043
// Start the API server
41-
api.StartServer(cfg, database, githubClient, workerPool)
44+
go api.StartServer(cfg, database, githubClient, workerPool)
45+
46+
// Set up graceful shutdown
47+
quit := make(chan os.Signal, 1)
48+
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
49+
<-quit
50+
51+
log.Println("Shutting down server...")
52+
53+
// Stop the worker pool
54+
workerPool.Stop()
55+
56+
log.Println("Server exiting")
4257
}
4358

4459
func runMigrations() error {

pkg/api/handlers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func GetWorkflowStats(c *gin.Context) {
7474
c.JSON(http.StatusBadRequest, gin.H{"error": "start_time must be before end_time"})
7575
return
7676
}
77+
7778
// Initialize counters
7879
totalRuns := len(runs)
7980
successCount := 0
@@ -125,5 +126,4 @@ func GetWorkflowStats(c *gin.Context) {
125126
"start_time": startTime.Format(time.RFC3339),
126127
"end_time": endTime.Format(time.RFC3339),
127128
})
128-
129129
}

0 commit comments

Comments
 (0)