Back

[Solved] Cloud function Fails to create index

  • 0
  • Databases
  • Functions
  • Cloud
kamal.panara
14 Jul, 2023, 15:27

now it got completed quickly

TL;DR
The user was experiencing an issue with a cloud function failing to create an index. The conversation includes discussions about handling the holding time, using teams and roles with Appwrite permissions, and different approaches to resolve the issue. The suggested solutions include using a scheduler approach, an event-driven approach, or an all-or-nothing approach. The user also discusses the function timing out after 15 seconds and asks about using self-hosted instead of the cloud. The conversation ends with the user thanking both participants and mentioning that the issue has been solved.
kamal.panara
14 Jul, 2023, 15:27

and got same error

kamal.panara
14 Jul, 2023, 15:28
TypeScript
{
    "success": false,
    "error": {
        "code": 400,
        "type": "attribute_not_available",
        "response": {
            "message": "Attribute not available: timestamp",
            "code": 400,
            "type": "attribute_not_available",
            "version": "0.10.45"
        }
    }
}
kamal.panara
14 Jul, 2023, 15:29

not sure how to fix this now.

Binyamin
14 Jul, 2023, 15:29

Yes, There is one more thing to add

Binyamin
14 Jul, 2023, 15:29

One sec I'll update the snippet

kamal.panara
14 Jul, 2023, 15:29

okay, thank you

Binyamin
14 Jul, 2023, 15:32

Done

kamal.panara
14 Jul, 2023, 15:32

okay, let me try again.

kamal.panara
14 Jul, 2023, 15:35

finally, it worked! πŸŽ‰

kamal.panara
14 Jul, 2023, 15:37

just putting my code here for future reference for other devs:

kamal.panara
14 Jul, 2023, 15:38
kamal.panara
14 Jul, 2023, 15:39

thank you so much both of you for helping me!!

kamal.panara
14 Jul, 2023, 15:39

[Solved] Cloud function Fails to create index

kamal.panara
14 Jul, 2023, 15:44

one last question,

kamal.panara
14 Jul, 2023, 15:45

what will happen when the attribute stays in a processing state for minutes?

kamal.panara
14 Jul, 2023, 15:46

because there is a function timeout of 15 seconds. so will it fail? or should I use self-hosted instead of cloud?

Drake
14 Jul, 2023, 16:07

you should make sure to handle that case. at the moment, on cloud, it can take up to 30 minutes when there is a db backup going on

Binyamin
14 Jul, 2023, 16:19

I'm no sure about your use case.

But, you can:

  • **Scheduler **approach - Use cronjobs for the indexing part, and, let that part being executed once every N minutes, that will work best with what Steven said about timing.
  • Event-driven approach - create a function that will trigger on the databases.*.collections.*.attributes.*.create event, then add an index to that attribute.
    • With this approach you'll get it even before the attribute is ready, so make sure to check it.
  • All-or-nothing approach - Do like the function you have here, and in cast ir fails just delete everything you've created.

It probably won't be good to extended the timeout time for a function like so.

If you need right now - as thing will, from what I've understand, be different when cloud's out of beta - then you can go the self-hosted route.

kamal.panara
14 Jul, 2023, 16:26

my use case is for one-one chat conversation.

kamal.panara
14 Jul, 2023, 16:28

every time when new user creates a chat, my cloud function executes and creates collection, storage bucket and all other stuff in the function code.

kamal.panara
14 Jul, 2023, 16:28

including index

kamal.panara
14 Jul, 2023, 16:29

so i can't make user wait for long. or else chat will not work

Binyamin
14 Jul, 2023, 16:32

I see, that's keep thing the same. You just need to choose the right approach to handle the holding time.

The other approach could be by using teams, roles and leverage Appwrite permission with few collections to start with, check these:

kamal.panara
14 Jul, 2023, 16:40

thanks for this, I have already a working chat system, just needed to fix that cloud function error. let me show you some screenshots, it's in Flutter and Appwrite.

I haven't used the Team feature yet, so I'm just giving permission to only conversation participants to access the conversation colletion.

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