I'm using the nodejs server sdk and awaiting for the attribute to be created and then I'm trying to add a document to the collection. But the await gets completed even with processing status and then when my server tries to add a document, unknown attribute error pops up.
Summary
The user is experiencing an issue where the attribute status remains as "processing" even after waiting for a certain amount of time. They have shared their code and mentioned that they added a delay using a promise, but the status still shows as "processing". Another user suggests that the API call returns when the job is queued and that the user will need to poll for when the status is available. The user confirms that they have added three more create attribute calls to create other attributes in the data given to create the document. However, the status still shows as "processing" and they receive an unknown attribute error when trying to add a document. No
Chandan Gowda
Rank 2: Process
Jun 16, 2023, 14:05
Plain text
newRoomDatabaseId,
"participants",
"isMicOn",
true
);
console.log(x.status);
await db.createDocument(
newRoomDatabaseId,
"participants",
roomData.admin_username,
{
isAdmin: true,
isModerator: true,
isSpeaker: true,
isMicOn: false,
}
);```
Chandan Gowda
Rank 2: Process
Jun 16, 2023, 14:32
x.status shows processing even after the async call gets completed
Chandan Gowda
Rank 2: Process
Jun 16, 2023, 14:33
And i have added three more create attribute calls to create other attributes in the data given to create the doc
Drake
Jun 16, 2023, 19:47
Yes, this is expected. The API call returns when the job is queued. You'll have to poll for when the status is available
Chandan Gowda
Rank 2: Process
Jun 17, 2023, 03:12
I checked the status after 40 seconds and its still under processing.
Chandan Gowda
Rank 2: Process
Jun 17, 2023, 03:12
Is there any other way to check if the attribute is available ?
Drake
Jun 17, 2023, 03:13
So right now it's still processing?
Chandan Gowda
Rank 2: Process
Jun 17, 2023, 03:13
Yeahh
Chandan Gowda
Rank 2: Process
Jun 17, 2023, 03:14
I just added a delay of 40 seconds and then checked the x.status . It show’s processing, but now the document gets added correctly.
Drake
Jun 17, 2023, 03:15
What do you mean you added a delay? And how are you checking the status?
Chandan Gowda
Rank 2: Process
Jun 17, 2023, 03:17
I added a time delay as a promise for 40 seconds and then when it resolves, Im just console logging x.status
Drake
Jun 17, 2023, 03:22
Can you share your code?
Chandan Gowda
Rank 2: Process
Jun 17, 2023, 03:43
Plain text
newRoomDatabaseId,
"participants",
"isMicOn",
true
);
console.log(x.status); //Prints processing
await new Promise(resolve => setTimeout(resolve, 5000));
console.log(x.status); //Prints processing
await db.createDocument(
newRoomDatabaseId,
"participants",
roomData.admin_username,
{
isMicOn: false,
}
);
console.log(x.status); //Prints processing```
Drake
Jun 17, 2023, 03:45
That doesn't work...you're just waiting and then looking at the same status string from when it was first created
Chandan Gowda
Rank 2: Process
Jun 17, 2023, 03:46
Can you please help me with what has to be done here to achieve my requirement?
Drake
Jun 17, 2023, 03:46
You need to fetch the attribute/collection again after waiting to see the new status
Chandan Gowda
Rank 2: Process
Jun 17, 2023, 04:27
Okayy. Thanks @Steven . Will check that in sometime.
Chandan Gowda
Rank 2: Process
Jun 17, 2023, 13:58
Hey @Steven
This is the algorithm I came up with.
// Polling until all the required attributes are added to the collection
while (true) {
let participantCollection = await db.getCollection(
newRoomDatabaseId,
"participants"
);
let attributesAvailable = true;
participantCollection.attributes.forEach((attribute) => {
if (attribute.status != "available") {
attributesAvailable = false;
}
});
if (attributesAvailable === true) {
break;
}
}
Chandan Gowda
Rank 2: Process
Jun 17, 2023, 13:58
It now works fine but I'm not sure if this is efficient. Need help in this regard.
Drake
Jun 17, 2023, 14:45
You should probably add some sort of delay between each iteration and set some sort of maximum so you don't get stuck in an infinite loop