Skip to content

Commit

Permalink
🔥this is fine🔥
Browse files Browse the repository at this point in the history
  • Loading branch information
ghophp committed Nov 20, 2023
1 parent 2490d7f commit 29d0faf
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,26 @@ func main() {
stream := ffmpeg.NewStream(twitchStreamKey, filepath.Join(basePath, "tmp", "playlist.txt"))
mixer := replicate.NewMixer(replicateKey, awsBaseUrl, faceVideoUrl, http.DefaultClient, fs)

// Create a server instance
server := &http.Server{Addr: ":" + port}
http.HandleFunc("/", healthCheckHandler)

go func() {
http.HandleFunc("/", healthCheckHandler)
fmt.Println("Server is running on port " + port)
http.ListenAndServe(":"+port, nil)
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
fmt.Printf("ListenAndServe error: %v\n", err)
}
}()

// Schedule a server shutdown after 30 minutes to give change for a new instance come up fresh
// It seems that CPU usage is high when the server is running for a long time 🔥this is fine🔥
time.AfterFunc(30*time.Minute, func() {
fmt.Println("Shutting down server...")
if err := server.Shutdown(context.Background()); err != nil {
fmt.Printf("Server Shutdown Failed:%+v", err)
}
})

go func() {
log.Println("Starting stream...")
err := stream.StartStream()
Expand Down

0 comments on commit 29d0faf

Please sign in to comment.