
Hello again, i open this new post because the other posts about execution timeout are about functions that sometimes freezes and throw the execution timeout error.
While my error is the same error, is not the same behavior, my problem is that the time i set on the timeout is not applied if i set more than 30 secs.. It is suppose that Maximum value is 900 secs, but, if the executions exceed more than 30 secs it fails and do not matter if i set timeout of 40,60,120 secs, it always fails at 30secs
A simple test is with php function and put a sleep(40) and set execution timeout to 120 secs, it will always fails at 30 secs
Im on AppWrite 1.5.13 self-Hosted

Why does this need to be synchronous?

because there is no way to create atributes when creating a collection, also, some created documents needs ids of created collections or other documents, they need to create everything in specific order

I don't really advise creating collections at runtime like this. Especially trying to do it synchronously. There are other occasions where the creation can take longer than 30 seconds like if you had a high load

Also, are you creating everything one by one serially? If so, that's inefficient

what did you suggest?

Why do you need to create collections at runtime? What's your database design?

As for this.. create things concurrently when possible. For example, you can create all collections and all non-relationship attributes concurrently

actually not, you need to create first all collections, then all non-rel attributes but you need to wait the creation of all collections to proceed to the attributes, then create rel-attributes, then create documents, then bucket then documents updates, so only some part would be async but others needs to be one by one, idk if this help to reduce time, i will try to do that

but to do that i will need another runtime, not php

Yes, of course, you can't do everything concurrently...that's why I said do it concurrently when possible

You could try using swoole...but, yes, a different runtime would be better

Thanks Steven

What is the swoole website ? There are too many swoole projects 😣😣

Should be https://openswoole.com/

I decided to re-write my function using nodejs, but how do you handle the creation of 100+ attributes? this is what i have:
const newdatabase = await databases.create(ID.unique(),name);
if(newdatabase && newdatabase.$id){
//Database created, now start creation of collections
const colloneprom = databases.createCollection(newdatabase.$id,'one','one',perms);
const colltwoprom = databases.createCollection(newdatabase.$id,'two','two',perms);
const collthreeprom = databases.createCollection(newdatabase.$id,'three','three',perms);
const collfourprom = databases.createCollection(newdatabase.$id,'four','four',perms);
Promise.all([colloneprom,colltwoprom,collthreeprom,collfourprom])
.then(([collone,colltwo,collthree,collfour]) =>{
//All collections are created, now add all attributes```
Do i need to create a const for each attribute and then another Promise.all so we can continue with the next step (create documents)?
`const attributeonecollone = databases.createStringAttribute(newdatabase.$id,collone.$id,'name',100, true);`
Or how to handle the creation of all attributes to then create documents?

I ended with something like this using nodejs; all collections, all attributes (simple and relationship attributes), and bucket are created in matter of seconds now, but i have two issues:
- The creation of the documents always fails, they fails with error: Unknown attribute: "xxxx" where "xxxx" is random every time i execute the function, also is random the creation of the document that fails, my guess is that attributes are not populated¿? or they are not immediately recognized by appwrite? checking console, the database, collections and all attributes exists
- Permissions are only set to 'admin' not to the 2nd user that the
permss
variable has


For test purposes, im listing the attributes on the collections that i want to create docs before create the documents:
log(collone: ${JSON.stringify(await databases.listAttributes(newdatabase.$id,'collone'),null,2)});
log(colltwo: ${JSON.stringify(await databases.listAttributes(newdatabase.$id,'colltwo'),null,2)});
log(collthree: ${JSON.stringify(await databases.listAttributes(newdatabase.$id,'collthree'),null,2)});
Log shows all the attributes correctly, but then it try to create the cocuments, and it still failled with the Error:
Invalid document structure: Unknown attribute: "xxxx"
(xxxx is random)
So, i can confirm that attributes are there before create the document, but createDocument fails for unknown attribute error...

IDK if this help, but this is AppWrite container log:
[Error] Method: POST
[Error] URL: /v1/databases/:databaseId/collections/:collectionId/documents
[Error] Type: Appwrite\Extend\Exception
[Error] Message: Invalid document structure: Unknown attribute: "name"
[Error] File: /usr/src/code/app/controllers/api/databases.php
[Error] Line: 2918
[Error] Timestamp: 2024-03-28T23:33:44+00:00
[Error] Method: POST
[Error] URL: /v1/databases/:databaseId/collections/:collectionId/documents
[Error] Type: Appwrite\Extend\Exception
[Error] Message: Invalid document structure: Unknown attribute: "name"
[Error] File: /usr/src/code/app/controllers/api/databases.php
[Error] Line: 2918```

I confirm my theory about that the attributes are not populated or are not immediately recognized by appwrite and/or createDocument(), i have been execute my function multiple times to see what happens, and as i see in past, the Unknown attribute changes, but, sometimes one or two of the documents are created without problems, listAttributes() returns all the attributes 100% of the time, and createDocument() is executed after the listAttributes() so, createDocument() should not fail with the Unknown attribute error, but it fails...

Did you check the status of the attribute to make sure they're available and not processing?

Yes, i make a call to listattributes before

.

Ok, i ended creating a new function:
let attributeStatus;
while (true) {
const allatt = await databases.listAttributes(db, col);
const attribute = allatt.attributes.find(attr => attr.key === att);
if (attribute) {
attributeStatus = attribute.status;
if (attributeStatus === 'available') {
break;
}
}
// Wait for a certain amount of time before checking again
await new Promise(resolve => setTimeout(resolve, 1000)); // Adjust the delay as needed
}
log(`The attribute "${att}" of collection "${col}" is available now!`);
}```
and called it before create the documents and indexed, i call it only for needed attributes (17):
`waitforatt(newdatabase.$id, 'collone', 'name');`
now it works, it creates everything... but, only if i execute it from console, if i execute it from web sdk, it fails if it pass the 30secs, so at the end i have the same problem as the php... 😩 it dont respect the timeout i set on console, it breaks at 30secs exactly
Recommended threads
- Failed to verify JWT. Invalid token: Exp...
Hi I am trying to call a function from my mobile app, but I am receiving "Invalid token expired." My code looks more or less like this ```ts // from my app ...
- Unable to View / Edit Bucket Files
Hi! I am unable to view / edit Bucket Files. While Previews work just fine, clicking the actual file to view or edit it produces the errors seen in the attache...
- How to remove the Sign up link after cre...
Greetings, i just installed appwrite on a VPS and created an account but now i do not want others to have access to the sign-up page. Is there any way to hide o...
