2026-03-05 00:04:26 -06:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"log"
|
|
|
|
|
"overlord-client/cmd/agent/runtime"
|
|
|
|
|
"overlord-client/cmd/agent/wire"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func HandlePing(ctx context.Context, env *runtime.Env, envelope map[string]interface{}) error {
|
2026-03-08 16:08:04 -05:00
|
|
|
|
2026-07-09 13:55:36 -05:00
|
|
|
ts, ok := extractTimestampIfPresent(envelope["ts"])
|
|
|
|
|
if !ok {
|
2026-03-05 00:04:26 -06:00
|
|
|
ts = time.Now().UnixMilli()
|
|
|
|
|
}
|
2026-04-07 10:43:27 -05:00
|
|
|
env.SetLastPong(time.Now().UnixMilli())
|
|
|
|
|
|
2026-03-05 00:04:26 -06:00
|
|
|
pong := wire.Pong{Type: "pong", TS: ts}
|
2026-04-06 18:04:45 -05:00
|
|
|
go func() {
|
2026-04-07 13:26:52 -05:00
|
|
|
defer recoverAndLog("pong sender", nil)
|
2026-04-06 18:04:45 -05:00
|
|
|
if err := wire.WriteMsg(ctx, env.Conn, pong); err != nil {
|
|
|
|
|
log.Printf("ping: failed to send pong: %v", err)
|
|
|
|
|
}
|
|
|
|
|
}()
|
2026-03-05 00:04:26 -06:00
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|