@@ -30,6 +30,7 @@ import (
30
30
"net/http/cookiejar"
31
31
"net/url"
32
32
"os"
33
+ "os/signal"
33
34
"sort"
34
35
"strings"
35
36
"time"
@@ -148,7 +149,18 @@ func pollAsyncJob(r *Request, jobID string) (map[string]interface{}, error) {
148
149
spinner := r .Config .StartSpinner ("polling for async API result" )
149
150
defer r .Config .StopSpinner (spinner )
150
151
152
+ interrupted := false
153
+ c := make (chan os.Signal , 1 )
154
+ signal .Notify (c , os .Interrupt )
155
+ go func () {
156
+ <- c
157
+ interrupted = true
158
+ }()
159
+
151
160
for {
161
+ if interrupted {
162
+ return nil , errors .New ("API job query interrupted" )
163
+ }
152
164
select {
153
165
case <- timeout .C :
154
166
return nil , errors .New ("async API job query timed out" )
@@ -234,8 +246,8 @@ func NewAPIRequest(r *Request, api string, args []string, isAsync bool) (map[str
234
246
config .Debug ("NewAPIRequest API request URL:" , requestURL )
235
247
236
248
var response * http.Response
237
- response ,err = executeRequest (r , requestURL , params )
238
- if ( err != nil ) {
249
+ response , err = executeRequest (r , requestURL , params )
250
+ if err != nil {
239
251
return nil , err
240
252
}
241
253
config .Debug ("NewAPIRequest response status code:" , response .StatusCode )
@@ -251,8 +263,8 @@ func NewAPIRequest(r *Request, api string, args []string, isAsync bool) (map[str
251
263
requestURL = fmt .Sprintf ("%s?%s" , r .Config .ActiveProfile .URL , encodeRequestParams (params ))
252
264
config .Debug ("NewAPIRequest API request URL:" , requestURL )
253
265
254
- response ,err = executeRequest (r , requestURL , params )
255
- if ( err != nil ) {
266
+ response , err = executeRequest (r , requestURL , params )
267
+ if err != nil {
256
268
return nil , err
257
269
}
258
270
}
@@ -281,7 +293,7 @@ func NewAPIRequest(r *Request, api string, args []string, isAsync bool) (map[str
281
293
}
282
294
283
295
// we can implement further conditions to do POST or GET (or other http commands) here
284
- func executeRequest (r * Request , requestURL string , params url.Values ) (* http.Response , error ){
296
+ func executeRequest (r * Request , requestURL string , params url.Values ) (* http.Response , error ) {
285
297
if params .Has ("password" ) || params .Has ("userdata" ) {
286
298
requestURL = fmt .Sprintf ("%s" , r .Config .ActiveProfile .URL )
287
299
return r .Client ().PostForm (requestURL , params )
0 commit comments