Skip to content
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

Asynchronious reporting data requests ("GoogleAdsServiceClient->searchAsync()") #701

Open
hakimio opened this issue Dec 14, 2021 · 3 comments
Labels
enhancement New feature or request P3 Prospects for future development or feature requests that would be nice to have. Typos or minor bugs

Comments

@hakimio
Copy link

hakimio commented Dec 14, 2021

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:

@hakimio hakimio added enhancement New feature or request triage Need triage labels Dec 14, 2021
@PierrickVoulet
Copy link
Collaborator

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?

@PierrickVoulet PierrickVoulet removed the triage Need triage label Dec 14, 2021
@hakimio
Copy link
Author

hakimio commented Dec 14, 2021

Use case is simple: downloading multiple reports in parallel to cache them in local database.

@hakimio
Copy link
Author

hakimio commented Dec 15, 2021

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.

@PierrickVoulet PierrickVoulet added the P3 Prospects for future development or feature requests that would be nice to have. Typos or minor bugs label Dec 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P3 Prospects for future development or feature requests that would be nice to have. Typos or minor bugs
Projects
None yet
Development

No branches or pull requests

2 participants