Readmore
Readmore
Readmore
arrows
arrows
arrows
Watchvideo
Visitblog
Visitservices
Visitwork
Engineering

Google Ads API batch job polling

Google is sunsetting the AdWords API on April 27, 2022. With it being right around the corner, my gut is telling me we’re not the only ones who are competing with the deadline to migrate to the new Google Ads API.

Angela Celar 3 years ago
dots dots

Google is sunsetting the AdWords API on April 27, 2022. With it being right around the corner, my gut is telling me we’re not the only ones who are competing with the deadline to migrate to the new Google Ads API. We have been working on it for the past few months and ran into a spectrum of problems to understand the new API which lacks documentation on some more complicated operations. So I wanted to share a simpler solution of polling a batch job executed on Google Ads API than the one in the documentation.

This is what Google recommends doing:

Google polling

It seemed wrong and I couldn’t bear to do what Google did on this one! Even though we are using asyncio, the _poll_batch_job() is a synchronous function and cannot be awaited. 

BatchJobService provides a way to execute batches of operations without synchronously waiting for every operation to complete. Submitted batch jobs run in parallel and what Google is suggesting here is to create a new thread for every job and wait for the batch job operation result. Considering you probably want to use batch jobs to reduce wait time for any operation to be completed, and creating multiple threads can lead to memory overhead, the cost of your application is going to increase and using batch jobs will not be enough. Just let the batch job operation do its thing.  


Batch job operation is a long-running operation that is the result of a network API call and there is this beautiful thing:

long-running operation

So we came up with a slightly different approach to polling batch job operation until done:

poll batch job

using batch_job.done() to check if the batch job operation has completed. Even if we are limiting the poll wait with MAX_POLL_ATTEMPTS, the resources are not going to be wasted while just waiting on a long running operation to finish.

Using asyncio.sleep() is going to give us the benefits of a scheduled callback of call_soon_threadsafe() without overcomplicating a simple thing such as polling the batch job by its status.

Since the Google Ads API is fairly new, I expect from Google to update the documentation and to recommend doing something like Operation.done() for polling any long-running operation. Batch jobs continue to be one of the most valuable features for Google Ads automation as it was the case on the AdWords API. 



Newsletter

We’ll need your email If you want to hear our two cents on the industry’s latest. We’re certain it will be worth your time, well, at least worth more than two cents.