go-vcloud-director
go-vcloud-director copied to clipboard
use context.Context for timing out operations
Currently there's no way to set a timeout for an operation using this library. Generally this is done in Go using the context package: https://blog.golang.org/context
In a fork I've begun adding context everywhere that needs it. If you are interested in this change upstream let me know and I can put a PR up when it's done, otherwise I'll just use the fork since I need the timeouts.
Hello @jakecoffman, Thanks for looking into it. I wonder what is your approach for cancellation? Are you cancelling tasks or something more?
Would be interesting to see your fork/branch
Here's an in-progress branch: https://github.com/vmware/go-vcloud-director/compare/master...jakecoffman:context
I need to cancel the underlying HTTP request (by using http.NewRequestWithContext), not the command or task itself. That way when my server that makes calls to vcloud needs to go down, if it happened to just launch a long running operation it can cancel and clean things up before it's killed.
Unfortunately by switching to http.NewRequestWithContext we have to pass a Context down from every function that calls it, which is nearly every function in this project.
It will be useful for using with tracing.
vcdclient.Client.Http.Transport = &ochttp.Transport{
Base: vcdclient.Client.Http.Transport,
}
Now, without context, i have separated traces.
I have a fork here with the context applied if anyone would like to use it before it is available in this repo: https://github.com/wwt/go-vcloud-director