Closed danielglh closed 1 year ago
BTW, I wrote a simple helper function for this fix
import _ from 'lodash';
export const reportStream = async function* (customer, queryOptions) {
const totalCount = await customer.reportCount(_.cloneDeep(queryOptions));
const stream = customer.reportStream(_.cloneDeep(queryOptions));
let rowCount = 0;
for await (const row of stream) {
yield row;
rowCount += 1;
if (rowCount >= totalCount) {
break;
}
}
}
It seems to do the trick but I'd still like to confirm whether this is the right way to solve it. Seem kinda hacky.
We started to experience the issue this week. Sometimes the
reportStream
for loop didn't end and just hang there when there's really no further data to fetch.Code is like this:
When I ran the code, it hung after the count reached the exact count of keywords in that account (I got the count from the Google Ads dashboard).
Right now we are trying the hack to use
reportCount
to get the count first and then break from the loop when we know all data has been fetched, but previously we don't need to do that, and it's not happening to allreportStream
calls.The hacking way:
I'm not sure if this is a hack or it's the correct way to do so. If it's not, what would be the correct way to handle streams?