Skip to content

Commit

Permalink
quick fix
Browse files Browse the repository at this point in the history
  • Loading branch information
NorseGaud committed Apr 8, 2024
1 parent b2eb1a0 commit 81f4288
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ var (
signalFlag = flag.String("s", "", `Send signal to the daemon:
drain — graceful shutdown, will wait until all jobs finish before exiting
stop — best effort graceful shutdown, interrupting the job as soon as possible`)
stop = make(chan struct{})
done = make(chan struct{})
stop = make(chan struct{})
done = make(chan struct{})
shutDownMessage = "anklet service shut down"
)

func termHandler(ctx context.Context, logger *slog.Logger) daemon.SignalHandlerFunc {
Expand Down Expand Up @@ -130,8 +131,6 @@ func main() {
if err != nil {
log.Printf("Error: %s", err.Error())
}

logger.InfoContext(ctx, "anklet terminated")
}

func worker(ctx context.Context, logger *slog.Logger, rateLimiter *http.Client, loadedConfig config.Config) {
Expand Down Expand Up @@ -201,20 +200,24 @@ func worker(ctx context.Context, logger *slog.Logger, rateLimiter *http.Client,
})
}

logger.InfoContext(serviceCtx, "started service")

for {
select {
case <-serviceCtx.Done():
logger.WarnContext(serviceCtx, "service shut down")
os.Exit(0)
logger.WarnContext(serviceCtx, shutDownMessage)
return
default:
run.Plugin(serviceCtx, logger)
if ctx.Err() != nil || runOnce == "true" {
logger.WarnContext(serviceCtx, "service shut down")
os.Exit(0)
logger.WarnContext(serviceCtx, shutDownMessage)
return
}
time.Sleep(time.Duration(service.SleepInterval) * time.Second)
}
}
}(service)
}
wg.Wait()
os.Exit(0)
}

0 comments on commit 81f4288

Please sign in to comment.