9

When long running operations are kicked off in Google Cloud APIs, the service might return an object with an "Operations" shape. The status of the operation can then be polled through this object and the results obtained when complete.

I'd like to avoid having to setup my own polling process for those results and I'm hoping that the Google Cloud Pub/Sub service can be leveraged to help. My hope comes from reading this line in the doc:

(emphasis added)

... the client can use this interface to receive the real response asynchronously by polling the operation resource, or pass the operation resource to another API (such as Google Cloud Pub/Sub API) to receive the response. ...

Is it possible to use the Google Cloud Pub/Sub API to be notified of a long running operation completion event? And how should I go about doing this?

I am unable to find any further reference or example use of this concept anywhere. Maybe I'm mis-interpreting that documentation line?

Cheers

ximus
  • 386
  • 3
  • 11
  • if this is possible, I would then have a Google Cloud Function listen for that Pub/Sub message and handle the results – ximus Jun 15 '17 at 12:54

1 Answers1

1

Do the long running operations you want to use write the results to a cloud storage bucket? If so you might be able to create a cloud function triggered by events on that bucket according to this page.

dizcology
  • 170
  • 7
  • Good thought but no, I'm targeting the speech to text async API and it does not write results to GCS. – ximus Jun 21 '17 at 04:34
  • Thank you for the clarification. The completion of a long running operation does not seem to emit/push any visible events. The paragraph you highlighted seems to simply mean that you could pass the name of the long running operation to another service which can then handle its own polling through service discovery. – dizcology Jun 21 '17 at 20:46
  • ah ok thanks, I was hoping it meant that the PubSub API can receive a reference to a long running operation "resource" and publish an message when that operation is done. Oh well – ximus Jun 22 '17 at 17:36
  • That would be really handy, actually, but I don't think it is currently supported. If you are up to writing your own simple polling service, this answer here contains some code snippet for retrieving the long running operation by its name: https://stackoverflow.com/a/44693613/4231563 – dizcology Jun 22 '17 at 18:36