worker: Use miner session for connectivity check

This commit is contained in:
Łukasz Magiera 2020-10-18 17:56:29 +02:00
parent cf4dfa3a05
commit 879aa9512d

View File

@ -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,6 +465,17 @@ 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()
for {
curSession, err := nodeApi.Session(ctx)
if err != nil {
log.Errorf("heartbeat: checking remote session failed: %+v", err)
} else {
if curSession != minerSession {
minerSession = curSession
break
}
if !connected {
if err := nodeApi.WorkerConnect(ctx, "http://"+address+"/rpc/v0"); err != nil { if err := nodeApi.WorkerConnect(ctx, "http://"+address+"/rpc/v0"); err != nil {
log.Errorf("Registering worker failed: %+v", err) log.Errorf("Registering worker failed: %+v", err)
cancel() cancel()
@ -456,14 +483,15 @@ var runCmd = &cli.Command{
} }
log.Info("Worker registered successfully, waiting for tasks") log.Info("Worker registered successfully, waiting for tasks")
connected = true
select { }
case <-closing:
case <-ctx.Done():
} }
if ctx.Err() != nil { select {
case <-ctx.Done():
return // graceful shutdown return // graceful shutdown
case <-heartbeats.C:
}
} }
log.Errorf("LOTUS-MINER CONNECTION LOST") log.Errorf("LOTUS-MINER CONNECTION LOST")