blob: c2625a550d0024e567d3a26babf7d140f44c14ef [file] [log] [blame]
Giorgi Lekveishvili378ea882023-12-12 13:59:18 +04001package tasks
2
3import (
4 "fmt"
5 "net/http"
6 "time"
gioe72b54f2024-04-22 10:44:41 +04007
8 phttp "github.com/giolekva/pcloud/core/installer/http"
Giorgi Lekveishvili378ea882023-12-12 13:59:18 +04009)
10
gioe72b54f2024-04-22 10:44:41 +040011func waitForAddr(client phttp.Client, addr string) Task {
Giorgi Lekveishvili378ea882023-12-12 13:59:18 +040012 t := newLeafTask(fmt.Sprintf("Wait for %s to come up", addr), func() error {
13 for {
gioe72b54f2024-04-22 10:44:41 +040014 if resp, err := client.Get(addr); err != nil || resp.StatusCode != http.StatusOK {
Giorgi Lekveishvili378ea882023-12-12 13:59:18 +040015 time.Sleep(2 * time.Second)
16 } else {
17 return nil
18 }
19 }
20 })
21 return &t
22}