provisionning: close connection to DB in spooler function (#57023)
This commit is contained in:
parent
e599e1c5f8
commit
be9d312fc0
|
@ -1,13 +1,29 @@
|
|||
import functools
|
||||
import json
|
||||
import logging
|
||||
|
||||
from django.db import connection
|
||||
from django.db import close_old_connections, connection
|
||||
from uwsgidecorators import spool
|
||||
|
||||
import hobo.multitenant.settings_loaders # this will get imported via importlib but fail for some reason in a uwsgi job
|
||||
from hobo.provisionning.utils import NotificationProcessing
|
||||
|
||||
|
||||
def ensure_db(func):
|
||||
"""Emulate Django"s setup/teardown of database connections before/after
|
||||
each request"""
|
||||
|
||||
@functools.wraps(func)
|
||||
def f(*args, **kwargs):
|
||||
close_old_connections()
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
finally:
|
||||
close_old_connections()
|
||||
|
||||
return f
|
||||
|
||||
|
||||
def set_connection(domain):
|
||||
from hobo.multitenant.middleware import TenantMiddleware
|
||||
|
||||
|
@ -16,6 +32,7 @@ def set_connection(domain):
|
|||
|
||||
|
||||
@spool
|
||||
@ensure_db
|
||||
def provision(args):
|
||||
try:
|
||||
set_connection(args['domain'])
|
||||
|
|
Loading…
Reference in New Issue