Skip to content

Commit

Permalink
feat: ctrl+c handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mempirate committed Jun 12, 2022
1 parent 12e73c9 commit 7013250
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions chainservice/chainservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/chainbound/apollo/types"
)

const (
rpcUrl = "wss://arb-mainnet.g.alchemy.com/v2/5_JWUuiS1cewWFpLzRxdjgZM0yLA4Uqp"
)
// const (
// rpcUrl = "wss://arb-mainnet.g.alchemy.com/v2/5_JWUuiS1cewWFpLzRxdjgZM0yLA4Uqp"
// )

func newChainService() *ChainService {
// ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
Expand Down
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"context"
"fmt"
"os"
"os/signal"
"path"
"syscall"
"time"

_ "embed"
Expand Down Expand Up @@ -136,6 +138,7 @@ func Run(opts types.ApolloOpts) error {
defaultTimeout := time.Second * 30

service := chainservice.NewChainService(defaultTimeout, opts.RateLimit, cfg.Rpc)
setupCloseHandler(service)

out := output.NewOutputHandler()

Expand Down Expand Up @@ -193,3 +196,14 @@ func Run(opts types.ApolloOpts) error {

return nil
}

func setupCloseHandler(svc *chainservice.ChainService) {
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
logger.Warn().Msg("ctrl+c pressed, exiting...")
svc.DumpMetrics()
os.Exit(0)
}()
}

0 comments on commit 7013250

Please sign in to comment.