@@ -9,19 +9,17 @@ import (
9
9
"bytes"
10
10
"context"
11
11
"encoding/json"
12
- "fmt"
13
12
"net/http"
14
13
15
14
"github.com/golang/glog"
16
- "github.com/gorilla/websocket"
17
15
jsonresp "github.com/sylabs/json-resp"
18
16
)
19
17
20
- // Build submits a build job to the Build Service. The context controls the
18
+ // Submit sends a build job to the Build Service. The context controls the
21
19
// lifetime of the request.
22
- func (c * Client ) SubmitBuild (ctx context.Context , d Definition , libraryRef string , libraryURL string ) (rd ResponseData , err error ) {
20
+ func (c * Client ) Submit (ctx context.Context , d Definition , libraryRef string , libraryURL string ) (bi BuildInfo , err error ) {
23
21
24
- b , err := json .Marshal (RequestData {
22
+ b , err := json .Marshal (BuildRequest {
25
23
Definition : d ,
26
24
LibraryRef : libraryRef ,
27
25
LibraryURL : libraryURL ,
@@ -44,69 +42,9 @@ func (c *Client) SubmitBuild(ctx context.Context, d Definition, libraryRef strin
44
42
}
45
43
defer res .Body .Close ()
46
44
47
- err = jsonresp .ReadResponse (res .Body , & rd )
45
+ err = jsonresp .ReadResponse (res .Body , & bi )
48
46
if err == nil {
49
- glog .V (2 ).Infof ("Build response - id: %s, wsurl: %s, libref: %s" ,
50
- rd .ID , rd .WSURL , rd .LibraryRef )
47
+ glog .V (2 ).Infof ("Build response - id: %s, libref: %s" , bi .ID , bi .LibraryRef )
51
48
}
52
- return rd , err
53
- }
54
-
55
- // StreamOutput reads log output from the websocket URL. The context controls
56
- // the lifetime of the request.
57
- func (c * Client ) StreamOutput (ctx context.Context , wsURL string ) error {
58
- h := http.Header {}
59
- c .setRequestHeaders (h )
60
-
61
- ws , resp , err := websocket .DefaultDialer .Dial (wsURL , h )
62
- if err != nil {
63
- glog .V (2 ).Infof ("websocket dial err - %s, partial response: %+v" , err , resp )
64
- return err
65
- }
66
- defer ws .Close ()
67
-
68
- for {
69
- // Check if context has expired
70
- select {
71
- case <- ctx .Done ():
72
- return ctx .Err ()
73
- default :
74
- }
75
-
76
- // Read from websocket
77
- mt , msg , err := ws .ReadMessage ()
78
- if err != nil {
79
- if websocket .IsCloseError (err , websocket .CloseNormalClosure ) {
80
- return nil
81
- }
82
- glog .V (2 ).Infof ("websocket read message err - %s" , err )
83
- return err
84
- }
85
-
86
- // Print to terminal
87
- switch mt {
88
- case websocket .TextMessage :
89
- fmt .Printf ("%s" , msg )
90
- case websocket .BinaryMessage :
91
- fmt .Print ("Ignoring binary message" )
92
- }
93
- }
94
- }
95
-
96
- // GetBuildStatus gets the status of a build from the Remote Build Service
97
- func (c * Client ) GetBuildStatus (ctx context.Context , buildID string ) (rd ResponseData , err error ) {
98
- req , err := c .newRequest (http .MethodGet , "/v1/build/" + buildID , "" , nil )
99
- if err != nil {
100
- return
101
- }
102
- req = req .WithContext (ctx )
103
-
104
- res , err := c .HTTPClient .Do (req )
105
- if err != nil {
106
- return
107
- }
108
- defer res .Body .Close ()
109
-
110
- err = jsonresp .ReadResponse (res .Body , & rd )
111
49
return
112
50
}
0 commit comments