Basic polling helper function for long running operations/jobs
Several libraries with long running operation are lacking basic helper functions for polling
Considering that implementing exponential backoff properly is a 15 line affair which clutters up code it might be good to have a util function that properly implements exponential backoff and then allow things to call it, like in bigquery.job.Jobs
def wait(self):
utils.exponential_backoff(self.begin, self.reload, self.status)
I've also suggested this for things like long-running operations
@elibixby We have a utility like that now for system testing. We could move it (and maybe the error-based and result-based ones) into the library itself, which might look like:
from gcloud.retry import RetryInstanceState
def _job_done(job):
return job.state.lower() == 'done'
until_done = RetryInstanceState(_job_done)
class _BaseJob(object):
...
@until_done
def wait(self):
self.reload()
@dhermes We need to factor out the google.longrunning.operations bit, including making the name pattern and metadata lookup bits less smelly. If we did, then we could add an Operation.wait method.
@tseaver Good point. We could even return an Operation instance from async uploads for BigQuery and have the concept map across packages.
@bjwatson Another grpc / GAX request: can you release wrappers for google.longrunning? We have a hacky self-generated version, but would be much better off using one "from the horse's mouth."
Note that this is just the gRPC bits: we are already using the "bare" proto-generated stuff from googleapis_common_protos.
@tseaver That's currently a WIP for us at the GAX level. @garrettjonesgoogle is leading this effort.
If you just need the GRPC generated code, then I think we can do that for you quickly.
@bjwatson We can use the stub-based (gRPC stubs) approach without GAX for now: basically, all we need is a way to call GetOperation for polling purposes. Later on, it would be good if DeleteOperation and CancelOperation were possible (I don't think we have a usecase for ListOperations).
@tseaver I tried doing that today using an internal build server we setup to introduce more controllability into our release process (previously done on dev workstations with varying environments). Unfortunately, I hit a few issues. I'll try again tomorrow with help from @ethanbao and @geigerj.
gRPC longrunning package available here: https://pypi.python.org/pypi/grpc-google-longrunning-v2/
I think the VKit team is still working out the full story for "meta-APIs" like longrunning, so I'll hold off the GAX package if you guys don't need it now.
@geigerj Thanks! I'll work on folding it in. One thing I note is that the 0.8.1 release doesn't have the v2 in the path: is that intentional?
@tseaver The protos are unversioned, and the lack of version in the path is a direct consequence.
@geigerj OK, WFM.
Hmm, looks like the new distribution clashes with googlapis-common-protos-1.2.0:
$ grep "operations_pb2.py\>" .tox/py27/lib/python2.7/site-packages/*.dist-info/RECORD
.tox/py27/lib/python2.7/site-packages/googleapis_common_protos-1.2.0.dist-info/RECORD:google/longrunning/operations_pb2.py,sha256=SOUv_2E4dyO0andxMae0Ce2LYjysFCMEvjS6HbP25o0,14161
.tox/py27/lib/python2.7/site-packages/grpc_google_longrunning_v2-0.8.1.dist-info/RECORD:google/longrunning/operations_pb2.py,sha256=na0U-_LrfCX7_G6thyTkWalgp_FFL6CguljKrPg5G98,27703
so "last one installed" wins. :(
Ah, shoot. Didn't realize operations was already included in googleapis-common-protos. I will discuss with @bjwatson about how best to proceed. We could bundle the gRPC stub in a new release of googleapis-common-protos, but it would be a breaking change later if we decide that's not how we want to distribute googleapis-common-protos.
Sorry, I didn't notice that either.
@tseaver Are you okay with the version of LRO in googleapis-common-protos, or did you need them packaged separately for some reason?
AFAIK googleapis-common-protos does not use the grpc plugin, so there will be no grpc stub.
@tseaver Sorry for the confusion. If you were already rolling your own solution for the Operations service, please continue to use that -- I think we're going to abandon grpc-google-longrunning-v2 for now. We'll keep thinking about how longrunning integrates with Veneer Toolkit and update when we know more.
FYI for Java, my plan was to roll this into the Java equivalent of googleapis-common-protos, and I was going to use the grpc plugin on Operations. I think it would be best to make a simple rule that protos with no major version go into the common protos package.
SGTM. If that's the plan for Java, we can do the same for Python.
@garrettjonesgoogle I thought about that idea, but worried about adding the extra dependencies to googlapis-common-protos (which is currently blissfully unaware of grpcio and oauth2client: it only depends on grpcio).