Skip to content

Commit

Permalink
fix: order when ping arrive
Browse files Browse the repository at this point in the history
  • Loading branch information
gi8lino committed Jun 24, 2024
1 parent afac7c8 commit b1ce2be
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/alecthomas/kingpin/v2"
)

const version = "0.6.12"
const version = "0.6.13"

//go:embed web
var templates embed.FS
Expand Down
21 changes: 10 additions & 11 deletions pkg/handlers/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,26 @@ func Ping(logger logger.Logger, heartbeatStore *heartbeat.Store, notificationSto
http.Error(w, errMsg, http.StatusNotFound)
return
}

details := map[string]string{
"proto": r.Proto,
"clientIP": clientIP,
"method": r.Method,
"userAgent": r.UserAgent(),
}

msg := "got ping"
logger.Infof("%s %s", heartbeatName, msg)

hs := historyStore.Get(heartbeatName)
hs.Add(history.Beat, msg, details)

if h.Enabled != nil && !*h.Enabled {
http.Error(w, fmt.Sprintf("Heartbeat '%s' not enabled", heartbeatName), http.StatusServiceUnavailable)
return
}

hs := historyStore.Get(heartbeatName)

h.StartInterval(ctx, logger, notificationStore, hs)

details := map[string]string{
"proto": r.Proto,
"clientIP": clientIP,
"method": r.Method,
"userAgent": r.UserAgent(),
}
hs.Add(history.Beat, msg, details)

w.WriteHeader(http.StatusOK)
if _, err := w.Write([]byte("ok")); err != nil {
logger.Errorf("Failed to write response. %v", err)
Expand Down

0 comments on commit b1ce2be

Please sign in to comment.