Home > Mobile >  How can I change the database time-out period in django?
How can I change the database time-out period in django?

Time:06-24

I have django script which fetch the data from model.

try:   
    myuser = MyUser.objects.get(id=user_id)
except Exception as e:
    print(e)
    # do next process

Then, what I want to do is ,,,

  • When database is stopped or not reached, I want to catch and do next process.

However my program return the 502 immediately, because it reachs to the aws lambda's timeout.

2022-06-23 19:09:51 127.0.0.1 - - [23/Jun/2022 19:09:51] "POST /webhook HTTP/1.1" 502 -
Function 'MyDjangoFunction' timed out after 300 seconds
No response from invoke container for MyDjangoFunction
Invalid lambda response received: Lambda response must be valid json

So, my idea is set django - sql timeout shorter.

Is there any good method??

CodePudding user response:

What you're looking for it CONN_MAX_AGE:

https://docs.djangoproject.com/en/dev/ref/settings/#conn-max-age

For example:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'mydatabase',
        'USER': 'mydatabaseuser',
        'PASSWORD': 'mypassword',
        'HOST': '127.0.0.1',
        'PORT': '5432',
        'CONN_MAX_AGE': 30,
    }
}
  • Related