Skip to content

Commit

Permalink
improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
theruziev committed Jan 10, 2025
1 parent eb421e4 commit 843ec73
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 2 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ type rootCli struct {

func Run() {
err := godotenv.Load()
if err != nil {
if !errors.Is(err, os.ErrNotExist) {
log.Fatalf("failed to read env: %s", err)
}
if err != nil && !errors.Is(err, os.ErrNotExist) {
log.Fatalf("failed to read env: %s", err)
}

rootCliApp := &rootCli{}
Expand Down
8 changes: 4 additions & 4 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/signal"
"syscall"
"time"

"github.com/theruziev/starter/internal/app/server"
Expand All @@ -19,17 +20,16 @@ type serverCli struct {
func (s *serverCli) Run(cliCtx *contextCli) error {
logger := logx.NewLogger(cliCtx.LogLevel, cliCtx.IsDebug)
ctx := logx.WithLogger(context.Background(), logger)
ctx, cancel := signal.NotifyContext(ctx, os.Interrupt, os.Kill)
ctx, cancel := signal.NotifyContext(ctx, os.Interrupt, syscall.SIGTERM)
defer cancel()

cl := closer.NewCloser()
go func() {
<-ctx.Done()
logger.Warnf("graceful shutdown")
logger.Warn("graceful shutdown initiated")
closeCtx, closeCancel := context.WithTimeout(context.Background(), 10*time.Second)
defer closeCancel()
err := cl.Close(closeCtx)
if err != nil {
if err := cl.Close(closeCtx); err != nil {
logger.Errorf("failed to close server: %s", err)
}
}()
Expand Down

0 comments on commit 843ec73

Please sign in to comment.