Hi Team,
am currently integrating a feature that sends email lists to Google Ads
via API in a serverless environment. This function operates without control
over concurrency, processing batches of SHA256 hashed email addresses. It
checks for the existence of a User List with a given name; if absent, it
creates a new list and uploads users.
However, I am encountering a concurrency issue. When two instances run
concurrently with a new User List name, both attempt to create the User
List simultaneously, leading to duplicate lists. This duplication is a
critical issue for the project's success.
Below is the relevant TypeScript code snippet:
*User List ID Check and Retrieval:*
```typescript
async getUserListId(name: string) {
const resp = await this.search({
gaql: `SELECT user_list.id, user_list.resource_name FROM user_list WHERE
user_list.name = '${name}'`,
});
if (!resp.results || !resp.results.length) {
return undefined;
}
return resp.results[0].userList.id as string;
}
```
The ID is later converted to a resource name via `customers/${this.
customerId}/userLists/${id}`
*User List Creation (if ID not found):*
```typescript
async createUserList(
name: string,
description: string = 'A user list from Segment CDP',
) {
const resp = await this.userListMutation([
{
create: {
name: name,
description: description,
membershipStatus: "OPEN",
accessReason: "OWNED",
crmBasedUserList: {
uploadKeyType: 'CONTACT_INFO',
dataSourceType: 'FIRST_PARTY',
},
membershipLifeSpan: '10000',
eligibleForSearch: true,
},
},
]);
const body = await resp.json();
return body;
}
```
I am seeking advice on how to handle this concurrency issue effectively.
Specifically, how can I ensure that only one User List is created even when
multiple instances attempt to create a list with the same name
simultaneously?
Please note that the environment I am working on is extremely restrictive
an only allows me to access Typescript fetch api and NodeJS crypto library.
The only way I can make it work is some REST API feature I am not across.
Thank you for your assistance.
Best regards,
Saad
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups
"Google Ads API and AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/adwords-api/679af219-bcd9-4d2b-9307-3af533eadd43n%40googlegroups.com.