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:
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:
So we came up with a slightly different approach to polling batch job operation until done:
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.
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.