mirror of
https://github.com/eosswedenorg/thalos
synced 2026-07-03 11:53:41 +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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -41,6 +42,8 @@ var running bool = false
|
||||||
|
|
||||||
var VersionString string = "dev"
|
var VersionString string = "dev"
|
||||||
|
|
||||||
|
var exit chan bool
|
||||||
|
|
||||||
func readerLoop() {
|
func readerLoop() {
|
||||||
running = true
|
running = true
|
||||||
recon_cnt := 0
|
recon_cnt := 0
|
||||||
|
|
@ -101,7 +104,17 @@ func readerLoop() {
|
||||||
|
|
||||||
recon_cnt = 0
|
recon_cnt = 0
|
||||||
log.Infof("Connected, Start: %d, End: %d", shClient.StartBlock, shClient.EndBlock)
|
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,7 +129,8 @@ func run() {
|
||||||
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
|
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
|
||||||
|
|
||||||
// Wait for interrupt
|
// Wait for interrupt
|
||||||
sig := <-signals
|
select {
|
||||||
|
case sig := <-signals:
|
||||||
log.WithField("signal", sig).Info("Signal received")
|
log.WithField("signal", sig).Info("Signal received")
|
||||||
|
|
||||||
// Cleanly close the connection by sending a close message.
|
// Cleanly close the connection by sending a close message.
|
||||||
|
|
@ -124,6 +138,9 @@ func run() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Info("failed to send close message to ship server")
|
log.WithError(err).Info("failed to send close message to ship server")
|
||||||
}
|
}
|
||||||
|
case <-exit:
|
||||||
|
// Do nothing, just exit.
|
||||||
|
}
|
||||||
|
|
||||||
running = false
|
running = false
|
||||||
}
|
}
|
||||||
|
|
@ -139,6 +156,8 @@ func main() {
|
||||||
var err error
|
var err error
|
||||||
var chainInfo *eos.InfoResp
|
var chainInfo *eos.InfoResp
|
||||||
|
|
||||||
|
exit = make(chan bool)
|
||||||
|
|
||||||
showHelp := getopt.BoolLong("help", 'h', "display this help text")
|
showHelp := getopt.BoolLong("help", 'h', "display this help text")
|
||||||
showVersion := getopt.BoolLong("version", 'v', "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")
|
configFile := getopt.StringLong("config", 'c', "./config.yml", "Config file to read", "file")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue