s-alty
March 19, 2020, 6:47pm
1
I see the /operations/wait endpoint supports a timeout param:
https://linuxcontainers.org/lxd/docs/master/rest-api#10operationsuuidwait
But it’s not clear to me how that timeout gets surfaced at the api level when it expires.
A cursory scan of the code shows that the timeout expiring causes this waitFinal method to return false:
}
// Wait until timeout
if timeout > 0 {
timer := time.NewTimer(time.Duration(timeout) * time.Second)
select {
case <-op.chanDone:
return true, nil
case <-timer.C:
return false, nil
}
}
return false, nil
}
// UpdateResources updates the resources of the operation. It returns an error
// if the operation is not pending or running, or the operation is read-only.
func (op *Operation) UpdateResources(opResources map[string][]string) error {
if op.status != api.Pending && op.status != api.Running {
But I think it gets ignored by the caller:
id := mux.Vars(r)["id"]
timeout, err := shared.AtoiEmptyDefault(r.FormValue("timeout"), -1)
if err != nil {
return response.InternalError(err)
}
// First check if the query is for a local operation from this node
op, err := operations.OperationGetInternal(id)
if err == nil {
_, err = op.WaitFinal(timeout)
if err != nil {
return response.InternalError(err)
}
_, body, err := op.Render()
if err != nil {
return response.SmartError(err)
}
return response.SyncResponse(true, body)
Anyone know how to detect whether a timeout expired without the operation completing?
stgraber
(Stéphane Graber)
March 19, 2020, 7:33pm
2
stgraber@castiana:~$ lxc query /1.0/operations/014b8909-5cec-4b73-903f-7b231fc4657d/wait?timeout=2
{
"class": "task",
"created_at": "2020-03-19T15:32:42.329637042-04:00",
"description": "Creating container",
"err": "",
"id": "014b8909-5cec-4b73-903f-7b231fc4657d",
"location": "none",
"may_cancel": true,
"metadata": {
"download_progress": "rootfs: 51% (9.81MB/s)"
},
"resources": {
"containers": [
"/1.0/containers/blah"
],
"instances": [
"/1.0/instances/blah"
]
},
"status": "Running",
"status_code": 103,
"updated_at": "2020-03-19T15:32:55.088357752-04:00"
}
In this example, the timeout was hit and so you get the current operation state, which indicates it’s in fact still running per status
and status_code
.
s-alty
March 19, 2020, 7:52pm
3
Okay gotcha, so a 103 status code means the operation is still in progress.
https://linuxcontainers.org/lxd/docs/master/rest-api#status-codes
Thanks for the help.