Back

Create Attributes processing for a long time

  • 0
  • Self Hosted
Chandan Gowda
16 Jun, 2023, 14:04

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.

TL;DR
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
16 Jun, 2023, 14:05
TypeScript
    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
16 Jun, 2023, 14:32

x.status shows processing even after the async call gets completed

Chandan Gowda
16 Jun, 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
16 Jun, 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
17 Jun, 2023, 03:12

I checked the status after 40 seconds and its still under processing.

Chandan Gowda
17 Jun, 2023, 03:12

Is there any other way to check if the attribute is available ?

Drake
17 Jun, 2023, 03:13

So right now it's still processing?

Chandan Gowda
17 Jun, 2023, 03:13

Yeahh

Chandan Gowda
17 Jun, 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
17 Jun, 2023, 03:15

What do you mean you added a delay? And how are you checking the status?

Chandan Gowda
17 Jun, 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
17 Jun, 2023, 03:22

Can you share your code?

Chandan Gowda
17 Jun, 2023, 03:43
TypeScript
    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
17 Jun, 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
17 Jun, 2023, 03:46

Can you please help me with what has to be done here to achieve my requirement?

Drake
17 Jun, 2023, 03:46

You need to fetch the attribute/collection again after waiting to see the new status

Chandan Gowda
17 Jun, 2023, 04:27

Okayy. Thanks @Steven . Will check that in sometime.

Chandan Gowda
17 Jun, 2023, 13:58

Hey @Steven This is the algorithm I came up with.

TypeScript
// 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
17 Jun, 2023, 13:58

It now works fine but I'm not sure if this is efficient. Need help in this regard.

Drake
17 Jun, 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

Chandan Gowda
17 Jun, 2023, 15:24

Okayy. Will do that. Thanks @Steven

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more