Projet

Général

Profil

0001-provisionning-close-connection-to-DB-in-spooler-func.patch

Benjamin Dauvergne, 17 septembre 2021 11:44

Télécharger (1,47 ko)

Voir les différences:

Subject: [PATCH] provisionning: close connection to DB in spooler function
 (#57023)

 hobo/provisionning/spooler.py | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
hobo/provisionning/spooler.py
1
import functools
1 2
import json
2 3
import logging
3 4

  
4
from django.db import connection
5
from django.db import close_old_connections, connection
5 6
from uwsgidecorators import spool
6 7

  
7 8
import hobo.multitenant.settings_loaders  # this will get imported via importlib but fail for some reason in a uwsgi job
8 9
from hobo.provisionning.utils import NotificationProcessing
9 10

  
10 11

  
12
def ensure_db(func):
13
    """Emulate Django"s setup/teardown of database connections before/after
14
    each request"""
15

  
16
    @functools.wraps(func)
17
    def f(*args, **kwargs):
18
        close_old_connections()
19
        try:
20
            return func(*args, **kwargs)
21
        finally:
22
            close_old_connections()
23

  
24
    return f
25

  
26

  
11 27
def set_connection(domain):
12 28
    from hobo.multitenant.middleware import TenantMiddleware
13 29

  
......
16 32

  
17 33

  
18 34
@spool
35
@ensure_db
19 36
def provision(args):
20 37
    try:
21 38
        set_connection(args['domain'])
22
-