Asynchronious reporting data requests ("GoogleAdsServiceClient->searchAsync()")
Problem you are trying to solve:
I would like to be able to download multiple reports in parallel.
Solution you'd like:
Right now when you call GoogleAdsServiceClient->search() method it in turn calls GapicClientTrait->getPagedListResponse() and blocks execution because of the wait() call at the end of the method.
I would like to have non-blocking GoogleAdsServiceClient->searchAsync() method which would just return GuzzleHttp\Promise\PromiseInterface and allow you to choose when to wait() for the promise to be resolved.
Additional context:
Hi @hakimio,
Thank you for sending this enhancement request.
The implementation is owned by gax-php. Could you please elaborate a bit more on the use cases?
Use case is simple: downloading multiple reports in parallel to cache them in local database.
Proposed simple solution which works:
public function searchAsync(string $customerId, string $query, array $optionalArgs = []): PromiseInterface
{
$request = new SearchGoogleAdsRequest();
$requestParamHeaders = [];
$request->setCustomerId($customerId);
$request->setQuery($query);
$requestParamHeaders['customer_id'] = $customerId;
if (isset($optionalArgs['pageToken'])) {
$request->setPageToken($optionalArgs['pageToken']);
}
if (isset($optionalArgs['pageSize'])) {
$request->setPageSize($optionalArgs['pageSize']);
}
if (isset($optionalArgs['validateOnly'])) {
$request->setValidateOnly($optionalArgs['validateOnly']);
}
if (isset($optionalArgs['returnTotalResultsCount'])) {
$request->setReturnTotalResultsCount($optionalArgs['returnTotalResultsCount']);
}
if (isset($optionalArgs['summaryRowSetting'])) {
$request->setSummaryRowSetting($optionalArgs['summaryRowSetting']);
}
$requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders);
$optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader();
return $this->startCall('Search', SearchGoogleAdsResponse::class, $optionalArgs, $request);
}
startCall() method is from GapicClientTrait class.