Skip to content

Commit

Permalink
feat: add graceful termination
Browse files Browse the repository at this point in the history
  • Loading branch information
Alec Cunningham authored and Alec Cunningham committed Oct 24, 2024
1 parent 4d73151 commit 8b0b9d3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"log"
"os"
"os/exec"
"os/signal"
"syscall"

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

workerPool := worker.NewWorkerPool(database, cfg.WorkerPoolSize)
workerPool.Start()

// Start the API server
api.StartServer(cfg, database, githubClient, workerPool)
go api.StartServer(cfg, database, githubClient, workerPool)

// Set up graceful shutdown
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit

log.Println("Shutting down server...")

// Stop the worker pool
workerPool.Stop()

log.Println("Server exiting")
}

func runMigrations() error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func GetWorkflowStats(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": "start_time must be before end_time"})
return
}

// Initialize counters
totalRuns := len(runs)
successCount := 0
Expand Down Expand Up @@ -125,5 +126,4 @@ func GetWorkflowStats(c *gin.Context) {
"start_time": startTime.Format(time.RFC3339),
"end_time": endTime.Format(time.RFC3339),
})

}

0 comments on commit 8b0b9d3

Please sign in to comment.