Skip to content

Commit 079d76b

Browse files
committed
feat(volumes): add volume serve
1 parent 578495a commit 079d76b

4 files changed

Lines changed: 93 additions & 280 deletions

File tree

volumes/filer.go

Lines changed: 0 additions & 65 deletions
This file was deleted.

volumes/filer_test.go

Lines changed: 0 additions & 168 deletions
This file was deleted.

volumes/volumes.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
package volumes
33

44
import (
5+
"context"
56
"encoding/json"
67
"fmt"
8+
"time"
79

810
drycc "github.com/drycc/controller-sdk-go"
911
"github.com/drycc/controller-sdk-go/api"
@@ -78,6 +80,41 @@ func Expand(c *drycc.Client, appID string, volume api.Volume) (api.Volume, error
7880
return newVolume, reqErr
7981
}
8082

83+
// Serve serves an app's volume.
84+
func Serve(parent context.Context, c *drycc.Client, appID, name string) (context.Context, map[string]string, error) {
85+
u := fmt.Sprintf("/v2/apps/%s/volumes/%s/filer/_/bind", appID, name)
86+
res, err := c.Request("POST", u, nil)
87+
if err != nil {
88+
return nil, nil, err
89+
}
90+
defer res.Body.Close()
91+
var filer map[string]string
92+
if err = json.NewDecoder(res.Body).Decode(&filer); err != nil {
93+
return nil, nil, err
94+
}
95+
ctx, cancel := context.WithCancel(parent)
96+
go func() {
97+
defer cancel()
98+
for {
99+
select {
100+
case <-parent.Done():
101+
return
102+
default:
103+
u := fmt.Sprintf("/v2/apps/%s/volumes/%s/filer/_/ping", appID, name)
104+
res, err := c.Request("GET", u, nil)
105+
if err != nil {
106+
return
107+
}
108+
if err := res.Body.Close(); err != nil {
109+
return
110+
}
111+
time.Sleep(time.Second * 30)
112+
}
113+
}
114+
}()
115+
return ctx, filer, nil
116+
}
117+
81118
// Delete delete an app's Volume.
82119
func Delete(c *drycc.Client, appID string, name string) error {
83120
u := fmt.Sprintf("/v2/apps/%s/volumes/%s/", appID, name)

0 commit comments

Comments
 (0)