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.
newRoomDatabaseId,
"participants",
"isMicOn",
true
);
console.log(x.status);
await db.createDocument(
newRoomDatabaseId,
"participants",
roomData.admin_username,
{
isAdmin: true,
isModerator: true,
isSpeaker: true,
isMicOn: false,
}
);```
x.status shows processing even after the async call gets completed
And i have added three more create attribute calls to create other attributes in the data given to create the doc
Yes, this is expected. The API call returns when the job is queued. You'll have to poll for when the status is available
I checked the status after 40 seconds and its still under processing.
Is there any other way to check if the attribute is available ?
So right now it's still processing?
Yeahh
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.
What do you mean you added a delay? And how are you checking the status?
I added a time delay as a promise for 40 seconds and then when it resolves, Im just console logging x.status
Can you share your code?
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```
That doesn't work...you're just waiting and then looking at the same status string from when it was first created
Can you please help me with what has to be done here to achieve my requirement?
You need to fetch the attribute/collection again after waiting to see the new status
Okayy. Thanks @Steven . Will check that in sometime.
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;
}
}
It now works fine but I'm not sure if this is efficient. Need help in this regard.
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
Okayy. Will do that. Thanks @Steven
Recommended threads
- How to use dart workspaces to deploy a f...
Hello, I'm developing a Flutter application and I would like to leverage dart pub workspaces to deploy a function with a dart runtime as advertised here : http...
- Migration from Cloud to Self-Hosted not ...
Hello Appwrite Community, I've got the problem, that when I try to migrate my Appwrite Project from the cloud to my self-hosted Appwrite, that an API Key is mi...
- I can't migrate my project from Appwrite...
I'm having an issue migrating my Appwrite project to a self-hosted instance. The problem is that I've exceeded my read rate limit (or database read limit), so I...