add daemon timeout option, stop ytsync gracefully during daemon startup
This commit is contained in:
parent
f34354059f
commit
1b6c47c841
3 changed files with 23 additions and 3 deletions
|
@ -3,6 +3,7 @@ package jsonrpc
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
@ -124,6 +125,10 @@ func (d *Client) call(response interface{}, command string, params map[string]in
|
|||
return decode(result, response)
|
||||
}
|
||||
|
||||
func (d *Client) SetRPCTimeout(timeout time.Duration) {
|
||||
d.conn.SetHTTPClient(&http.Client{Timeout: timeout})
|
||||
}
|
||||
|
||||
func (d *Client) Commands() (*CommandsResponse, error) {
|
||||
response := new(CommandsResponse)
|
||||
return response, d.call(response, "commands", map[string]interface{}{})
|
||||
|
|
|
@ -13,11 +13,11 @@ func New() *Stopper {
|
|||
return &s
|
||||
}
|
||||
|
||||
func (s Stopper) Chan() <-chan struct{} {
|
||||
func (s *Stopper) Chan() <-chan struct{} {
|
||||
return s.ch
|
||||
}
|
||||
|
||||
func (s Stopper) Stop() {
|
||||
func (s *Stopper) Stop() {
|
||||
s.once.Do(func() {
|
||||
close(s.ch)
|
||||
})
|
||||
|
|
|
@ -134,7 +134,22 @@ func (s *Sync) FullCycle() error {
|
|||
}
|
||||
|
||||
log.Infoln("Waiting for daemon to finish starting...")
|
||||
s.daemon = jsonrpc.NewClientAndWait("")
|
||||
s.daemon = jsonrpc.NewClient("")
|
||||
s.daemon.SetRPCTimeout(5 * time.Minute)
|
||||
|
||||
WaitForDaemonStart:
|
||||
for {
|
||||
select {
|
||||
case <-s.stop.Chan():
|
||||
return nil
|
||||
default:
|
||||
_, err := s.daemon.WalletBalance()
|
||||
if err == nil {
|
||||
break WaitForDaemonStart
|
||||
}
|
||||
time.Sleep(5 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
err = s.doSync()
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Reference in a new issue