forked from bittorrent/go-btfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.go
29 lines (27 loc) · 918 Bytes
/
helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package spin
import (
"context"
"strings"
"time"
)
func periodicSync(period, timeout time.Duration, msg string, syncFunc func(context.Context) error) {
tick := time.NewTicker(period)
defer tick.Stop()
// Force tick on immediate start
for ; true; <-tick.C {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
err := syncFunc(ctx)
if err != nil {
if strings.Contains(err.Error(), "Cannot query to get stats, please wait for host validation") {
log.Infof("Currently syncing the BTFS network, " +
"which may last several hours depending on network conditions. Please be patient.")
} else if strings.Contains(err.Error(), "Cannot query to get hosts") {
log.Errorf("Cannot query to get hosts. " +
"If you are not a renter, i.e. don't need to upload files, you can ignore it.")
} else {
log.Errorf("Failed to sync %s: %s", msg, err)
}
}
}
}