
i have this cloud function it works like charm, but sometimes it weirdly timeout i even extended the timeout sequence but still to no avail.
TypeScript
import { Client, Databases, ID, Users } from 'node-appwrite';
export default async ({ req, res, log, error }) => {
const {orderId,message} = JSON.parse(req.body);
const client = new Client()
.setEndpoint(process.env.VITE_APPWRITE_ENDPOINT)
.setProject(process.env.VITE_APPWRITE_PROJECT)
.setKey(process.env.VITE_APPWRITE_API_KEY);
const databases = new Databases(client);
try {
const order = await databases.getDocument(
process.env.VITE_APPWRITE_DATABASE_ID_EKHLAS,
process.env.VITE_APPWRITE_COLLECTION_ORDERS_ID,
orderId
);
if(!order){
return res.send('Order not found');
}
const orderStatus = await databases.createDocument(
process.env.VITE_APPWRITE_DATABASE_ID_EKHLAS,
process.env.VITE_APPWRITE_COLLECTION_ORDER_STATUS_ID,
ID.unique(),
{
date: new Date(),
orderId: orderId,
status: 'REQUEST_MAINTENANCE'
}
);
if(!orderStatus){
return res.send('Order status not created');
}
const orderStatusIds = [
...order.orderStatus.map((status) => status.$id),
orderStatus.$id
]
const response = await databases.updateDocument(
process.env.VITE_APPWRITE_DATABASE_ID_EKHLAS,
process.env.VITE_APPWRITE_COLLECTION_ORDERS_ID,
orderId,
{
status: 'REQUEST_MAINTENANCE',
orderStatus: orderStatusIds,
maintenanceMessage: message ?? ""
}
);
if(!response){
return res.send('Order not updated');
}
return res.send('Order updated');
} catch (e) {
console.log(e);
return res.send(e);
}
};
this is my code.
TL;DR
Cloud function sometimes times out despite extending timeout sequence. The provided code seems valid and handles database operations. Consider optimizing the code for better performance, check the Node.js event loop for any bottlenecks.Recommended threads
- SDK mismatch
Hi there, The following warning is currently appearing in my console: ``` Warning: The current SDK is built for Appwrite 1.8.0. However, the current Appwrite...
- Can't read files from s3 storage directl...
I try to download the files stored by appwrite directly from my S3 provider. The bucket is not encrypted and no gzip but the files seem not to be stored there i...
- Appwrite messaging api error
```=== Push Notification Function Started === Endpoint: https://fra.cloud.appwrite.io/v1 Project: 6899062700398ffeae4f Database: threed-dating-db Notification f...
