worker: Use miner session for connectivity check
This commit is contained in:
parent
cf4dfa3a05
commit
879aa9512d
@ -431,17 +431,33 @@ var runCmd = &cli.Command{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
minerSession, err := nodeApi.Session(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("getting miner session: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
var reconnect bool
|
heartbeats := time.NewTicker(stores.HeartbeatInterval)
|
||||||
|
defer heartbeats.Stop()
|
||||||
|
|
||||||
|
var connected, reconnect bool
|
||||||
for {
|
for {
|
||||||
|
// If we're reconnecting, redeclare storage first
|
||||||
if reconnect {
|
if reconnect {
|
||||||
log.Info("Redeclaring local storage")
|
log.Info("Redeclaring local storage")
|
||||||
|
|
||||||
if err := localStore.Redeclare(ctx); err != nil {
|
if err := localStore.Redeclare(ctx); err != nil {
|
||||||
log.Errorf("Redeclaring local storage failed: %+v", err)
|
log.Errorf("Redeclaring local storage failed: %+v", err)
|
||||||
cancel()
|
|
||||||
return
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return // graceful shutdown
|
||||||
|
case <-heartbeats.C:
|
||||||
|
}
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connected = false
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("Making sure no local tasks are running")
|
log.Info("Making sure no local tasks are running")
|
||||||
@ -449,21 +465,33 @@ var runCmd = &cli.Command{
|
|||||||
// TODO: we could get rid of this, but that requires tracking resources for restarted tasks correctly
|
// TODO: we could get rid of this, but that requires tracking resources for restarted tasks correctly
|
||||||
workerApi.LocalWorker.WaitQuiet()
|
workerApi.LocalWorker.WaitQuiet()
|
||||||
|
|
||||||
if err := nodeApi.WorkerConnect(ctx, "http://"+address+"/rpc/v0"); err != nil {
|
for {
|
||||||
log.Errorf("Registering worker failed: %+v", err)
|
curSession, err := nodeApi.Session(ctx)
|
||||||
cancel()
|
if err != nil {
|
||||||
return
|
log.Errorf("heartbeat: checking remote session failed: %+v", err)
|
||||||
}
|
} else {
|
||||||
|
if curSession != minerSession {
|
||||||
|
minerSession = curSession
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
log.Info("Worker registered successfully, waiting for tasks")
|
if !connected {
|
||||||
|
if err := nodeApi.WorkerConnect(ctx, "http://"+address+"/rpc/v0"); err != nil {
|
||||||
|
log.Errorf("Registering worker failed: %+v", err)
|
||||||
|
cancel()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
select {
|
log.Info("Worker registered successfully, waiting for tasks")
|
||||||
case <-closing:
|
connected = true
|
||||||
case <-ctx.Done():
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Err() != nil {
|
select {
|
||||||
return // graceful shutdown
|
case <-ctx.Done():
|
||||||
|
return // graceful shutdown
|
||||||
|
case <-heartbeats.C:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Errorf("LOTUS-MINER CONNECTION LOST")
|
log.Errorf("LOTUS-MINER CONNECTION LOST")
|
||||||
|
Loading…
Reference in New Issue
Block a user