Taobin-Recipe-Manager/server/main.go
2023-11-16 11:03:26 +07:00

47 lines
848 B
Go

package main
import (
"context"
"log"
"os"
"os/signal"
"syscall"
"time"
)
func main() {
s := NewServer()
serverCtx, serverStopCtx := context.WithCancel(context.Background())
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
go func() {
<-sig
shutdownCtx, cancel := context.WithTimeout(serverCtx, 30*time.Second)
go func() {
<-shutdownCtx.Done()
if shutdownCtx.Err() == context.DeadlineExceeded {
log.Println("Shutdown timeout, force exit")
cancel()
}
}()
err := s.Shutdown(shutdownCtx)
if err != nil {
log.Fatal(err)
}
serverStopCtx()
}()
// Spawn a goroutine to run git pull every 10 minutes
//go RunGitRecipeWorker() // ** Use crontab instead **
err := s.Run()
if err != nil {
log.Fatal(err)
}
<-serverCtx.Done()
}