Skip to content

Commit

Permalink
Merge pull request #12 from itaru2622/issue11
Browse files Browse the repository at this point in the history
configurable liveness check interval to avoid frequent restarting
  • Loading branch information
ericvolp12 authored Oct 29, 2024
2 parents 75fdbaa + 80a8fa3 commit 75f2991
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cmd/jetstream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ func main() {
Value: -1,
EnvVars: []string{"JETSTREAM_OVERRIDE_RELAY_CURSOR"},
},
&cli.DurationFlag{
Name: "liveness-ttl",
Usage: "time to restart when no event detected",
Value: 15 * time.Second,
EnvVars: []string{"JETSTREAM_LIVENESS_TTL"},
},
}

app.Action = Jetstream
Expand Down Expand Up @@ -171,11 +177,11 @@ func Jetstream(cctx *cli.Context) error {
// Usually when a critical routine returns an error
livenessKill := make(chan struct{})

// Start a goroutine to manage the liveness checker, shutting down if no events are received for 15 seconds
// Start a goroutine to manage the liveness checker, shutting down if no events are received for liveness-ttl
shutdownLivenessChecker := make(chan struct{})
livenessCheckerShutdown := make(chan struct{})
go func() {
ticker := time.NewTicker(15 * time.Second)
ticker := time.NewTicker(cctx.Duration("liveness-ttl"))
lastSeq := int64(0)
log := log.With("source", "liveness_checker")

Expand All @@ -188,7 +194,7 @@ func Jetstream(cctx *cli.Context) error {
case <-ticker.C:
seq, _ := c.Progress.Get()
if seq == lastSeq && seq != 0 {
log.Error("no new events in last 15 seconds, shutting down for docker to restart me", "seq", seq)
log.Error("no new events in last "+ cctx.Duration("liveness-ttl").String() +", shutting down for docker to restart me", "seq", seq)
close(livenessKill)
} else {
// Trim the database
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ services:
- ./data:/data
environment:
- JETSTREAM_DATA_DIR=/data
# livness check interval to restart when no events are received (default: 15sec)
- JETSTREAM_LIVENESS_TTL=15s

0 comments on commit 75f2991

Please sign in to comment.