mirror of
https://github.com/eosswedenorg/thalos
synced 2026-06-18 04:40:03 +02:00
cmd/thalos/main.go: exit the program correctly if we get shipclient.ErrEndBlockReached
This commit is contained in:
parent
d0962a6c42
commit
fb54dd9960
1 changed files with 26 additions and 7 deletions
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
|
@ -41,6 +42,8 @@ var running bool = false
|
|||
|
||||
var VersionString string = "dev"
|
||||
|
||||
var exit chan bool
|
||||
|
||||
func readerLoop() {
|
||||
running = true
|
||||
recon_cnt := 0
|
||||
|
|
@ -101,7 +104,17 @@ func readerLoop() {
|
|||
|
||||
recon_cnt = 0
|
||||
log.Infof("Connected, Start: %d, End: %d", shClient.StartBlock, shClient.EndBlock)
|
||||
log.WithError(shClient.Run()).Error("Failed to read from ship")
|
||||
|
||||
if err := shClient.Run(); err != nil {
|
||||
|
||||
if errors.Is(err, shipclient.ErrEndBlockReached) {
|
||||
exit <- true
|
||||
log.Info("Endblock reached.")
|
||||
break
|
||||
}
|
||||
|
||||
log.WithError(err).Error("Failed to read from ship")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -116,13 +129,17 @@ func run() {
|
|||
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
// Wait for interrupt
|
||||
sig := <-signals
|
||||
log.WithField("signal", sig).Info("Signal received")
|
||||
select {
|
||||
case sig := <-signals:
|
||||
log.WithField("signal", sig).Info("Signal received")
|
||||
|
||||
// Cleanly close the connection by sending a close message.
|
||||
err := shClient.Shutdown()
|
||||
if err != nil {
|
||||
log.WithError(err).Info("failed to send close message to ship server")
|
||||
// Cleanly close the connection by sending a close message.
|
||||
err := shClient.Shutdown()
|
||||
if err != nil {
|
||||
log.WithError(err).Info("failed to send close message to ship server")
|
||||
}
|
||||
case <-exit:
|
||||
// Do nothing, just exit.
|
||||
}
|
||||
|
||||
running = false
|
||||
|
|
@ -139,6 +156,8 @@ func main() {
|
|||
var err error
|
||||
var chainInfo *eos.InfoResp
|
||||
|
||||
exit = make(chan bool)
|
||||
|
||||
showHelp := getopt.BoolLong("help", 'h', "display this help text")
|
||||
showVersion := getopt.BoolLong("version", 'v', "display this help text")
|
||||
configFile := getopt.StringLong("config", 'c', "./config.yml", "Config file to read", "file")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue