-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add LRO support #42
Add LRO support #42
Conversation
Thanks for this, Michael! I'm excited to get my hands on it. @dwsupplee and I agree that if an LRO completes with an error, it should not throw an exception. Instead, the response should be returned, and left to the implementor to deal with. If there is an error in any of the requests, (i.e. an invalid argument or a server error), those exceptions should certainly still be thrown. |
OK no worries. If we are returning either the response or error, do you prefer:
The reason to prefer either the second or third option over the first is to provide an easy way for people to check for success or failure, instead of having to interrogate the return type. Alternatively, we could provide helpers on the OperationResponse object, but this feels more awkward to me. Thanks for having a look so quickly! |
I should have been more careful in my previous comment. When I said "response", I was thinking in HTTP terms (i.e. response means the entire result returned from a call). I'd like to have the entire |
No worries, you are right that we should make the proto object available. I had intended to do that but missed that method :-( There is now an added method to get the operation proto object. That still leaves the question of what to return from the getResult() method, which I think is a useful helper so that it isn't necessary to get the operation proto in most cases. |
// Simple case | ||
$op = $sampleApi->longRunningRpc(); | ||
// ... do stuff ... | ||
$op->pollUntilComplete(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
// TODO: use poll settings | ||
sleep(1); | ||
$this->refresh(); | ||
} |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@michaelbausor WDYT about having I think explicitly choosing the result or the error makes it easier to prevent errors in mishandling an unexpected result (i.e. if you code around what a success should look like and instead get an error, will your code break?). $op = $sampleApi->longRunningRpc();
$op->pollUntilComplete();
if (!is_null($op->getError())) {
// handle errors
}
return $op->getResult(); |
I think that sounds sensible. That makes the OperationResponse object very similar in structure to the proto object, will helpers for refresh(), cancel(), pollUntilComplete() and using promises. |
@michaelbausor do we have the ability to make async calls with gRPC yet? If yes, it would be great if we could set some time aside to come up with a good plan for how to handle promises. For example, I have a WIP branch right now that introduces |
Not right now through Veneer toolkit, but I am looking into what would be required to add that support. Definitely it would be great to pick a time to discuss how we want to handle promises more generally - how about Thursday or Friday this week some time? |
Friday should work for me! |
Following up re status - it seems that the latest is your open issue in gRPC (grpc/grpc#6654), which hasn't been given a priority yet. So we aren't able to support async over gRPC at this time. But it would still be worth having the discussion so that we are on the same page. Friday sounds good, I have created an event at 10:30 PST as a placeholder, please edit or ping me if that doesn't work for you. |
Current coverage is 89.78% (diff: 88.15%)@@ master #42 diff @@
==========================================
Files 16 18 +2
Lines 1130 1341 +211
Methods 123 147 +24
Messages 0 0
Branches 0 0
==========================================
+ Hits 1011 1204 +193
- Misses 119 137 +18
Partials 0 0
|
Generate operations API, update operations wrapper Update operation and callable
@garrettjonesgoogle @shinfan PTAL for review before merging |
/** | ||
* The default address of the service. | ||
*/ | ||
const SERVICE_ADDRESS = 'longrunning.googleapis.com'; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
* | ||
* @type string $serviceAddress The domain name of the API remote host. | ||
* Default 'longrunning.googleapis.com'. | ||
* @type string $serviceAddress Required. The domain name of the API remote host. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking nice overall! Just a few comments and things I am curious on.
@@ -17,7 +17,8 @@ | |||
}, | |||
"autoload": { | |||
"psr-4": { | |||
"Google\\GAX\\":"src/" | |||
"Google\\GAX\\":"src/", | |||
"Google\\Longrunning\\":"src/Longrunning/" |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
* 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. Any API service that | ||
* returns long-running operations should implement the `Operations` interface |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
* ``` | ||
* | ||
* Many parameters require resource names to be formatted in a particular way. To assist | ||
* with these names, this class includes a format method for each type of name, and additionally |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
* Service Description: Manages long-running operations with an API service. | ||
* | ||
* When an API method normally takes long time to complete, it can be designed | ||
* to return [Operation][google.longrunning.Operation] to the client, and the client can use this |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
* ``` | ||
* | ||
* @param string $name The name of the operation collection. | ||
* @param string $filter The standard list filter. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
* Return true if the operation completed successfully, otherwise return | ||
* false. | ||
* | ||
* The $pollSettings optional argument can be used to control the polling loop. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
} | ||
|
||
/** | ||
* @return \google\longrunning\Operation The last Operation object received from the server. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
* Starts asynchronous cancellation on a long-running operation. The server | ||
* makes a best effort to cancel the operation, but success is not | ||
* guaranteed. If the server doesn't support this method, it will throw an | ||
* ApiException with code \google\rpc\Code::UNIMPLEMENTED. Clients can continue |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
$anyResponse = $this->lastProtoResponse->getResponse(); | ||
if (is_null($this->operationReturnType)) { | ||
return $anyResponse; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
* @param array $options { | ||
* Options for configuring the polling behaviour. | ||
* | ||
* @type float $pollingIntervalSeconds The polling interval to use, in seconds. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @dwsupplee !
I have made changes and/or commented, PTAL
* @param array $options { | ||
* Options for configuring the polling behaviour. | ||
* | ||
* @type float $pollingIntervalSeconds The polling interval to use, in seconds. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
The updates look great, nice work! |
* OperationResponse constructor. | ||
* | ||
* @param string $operationName | ||
* @param \Google\Longrunning\OperationsClient $operationsClient |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
} | ||
|
||
/** | ||
* @return \Google\Longrunning\OperationsClient The OperationsClient object used to make |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
* backwards compatibility. | ||
*/ | ||
|
||
namespace Google\GAX\Longrunning; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
- Change LRO namespace to camel case - Add license
PTAL |
This is a possible OperationResponse object for use with LRO in PHP. Some points to note: