File: wsgi.py

package info (click to toggle)
lava 2026.01-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 30,796 kB
  • sloc: python: 82,790; javascript: 16,658; sh: 1,364; makefile: 335
file content (31 lines) | stat: -rw-r--r-- 944 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Copyright (C) 2016-2018 Linaro Limited
#
# Author: Remi Duraffort <remi.duraffort@linaro.org>
#
# SPDX-License-Identifier: GPL-2.0-or-later

import os

from django.conf import settings
from django.core.wsgi import get_wsgi_application
from django.db.backends.signals import connection_created

# Set the environment variables for Django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lava_server.settings.prod")


# Set the postgresql connection timeout
# The timeout is only used when running through wsgi.  This way, command line
# commands are not affected by the timeout.
def setup_postgres(connection, **kwargs):
    if connection.vendor != "postgresql":
        return

    with connection.cursor() as cursor:
        cursor.execute("SET statement_timeout TO %s", (settings.STATEMENT_TIMEOUT,))


connection_created.connect(setup_postgres, dispatch_uid="setup_postgres")

# Create the application
application = get_wsgi_application()