Skip to content

Commit 70c6fb2

Browse files
Add waitforhosts function (#16)
* upgrade tailscale, add waitforhosts function * revert tailscale upgrade
1 parent adce9cf commit 70c6fb2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pkg/client.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,25 @@ func (c *BlobCacheClient) HostsAvailable() bool {
457457
return c.hostMap.Members().Cardinality() > 0
458458
}
459459

460+
func (c *BlobCacheClient) WaitForHosts(timeout time.Duration) error {
461+
ctx, cancel := context.WithTimeout(context.Background(), timeout)
462+
defer cancel()
463+
464+
Logger.Infof("Waiting for hosts to be available...")
465+
for {
466+
select {
467+
case <-ctx.Done():
468+
return ctx.Err()
469+
default:
470+
if c.HostsAvailable() {
471+
return nil
472+
}
473+
474+
time.Sleep(1 * time.Second)
475+
}
476+
}
477+
}
478+
460479
func (c *BlobCacheClient) GetState() error {
461480
ctx, cancel := context.WithTimeout(c.ctx, getContentRequestTimeout)
462481
defer cancel()

0 commit comments

Comments
 (0)