vercel / examples

Enjoy our curated collection of examples and solutions. Use these patterns to build your own robust and scalable applications.
MIT License
3.55k stars 1.09k forks source link

Django project enlarge timeout. #615

Open hengjiUSTC opened 1 year ago

hengjiUSTC commented 1 year ago

For https://github.com/vercel/examples/blob/main/python/django/vercel.json we have use case that some operations (open ai apis) takes longer than 10s. Currently vercel returns 504 error similar to https://community.openai.com/t/api-504s-in-production-vercel-only/28795/8. I tried to update vercel.json to

{
  "builds": [
    {
      "src": "vercel_app/wsgi.py",
      "use": "@vercel/python"
    }
  ],
  "routes": [
    {
      "src": "/(.*)",
      "dest": "vercel_app/wsgi.py"
    }
  ],
  "functions": {
    "bot/**/*": {
      "maxDuration": 60
    }
  }
}

But this won't work due to conflict of functions and builds. How could we fix this issue to enlarge timeout limit ?

chinmayroy commented 1 year ago

It seems like you are trying to increase the timeout limit for a specific function in your Vercel deployment. However, you are encountering an issue where the functions and builds are conflicting with each other.

One solution to this problem is to separate the long-running operation into its own Vercel function, rather than having it run as part of the Django app. You can create a separate directory for this function and define a new vercel.json file for it with the desired maxDuration value.

ms8909 commented 7 months ago

Above solution works. Create a simple python function and add the following in vercel.json file

"functions": { "api/*.py": { "maxDuration": 300 }