Commit 73e6d592 authored by Julien Muchembled's avatar Julien Muchembled

WSGI: do not use zserver threads for automatic creation of ERP5 site

parent ac31e8c9
...@@ -2429,18 +2429,16 @@ def initialize(self): ...@@ -2429,18 +2429,16 @@ def initialize(self):
for _ in self.getApp().objectIds(meta_type): for _ in self.getApp().objectIds(meta_type):
return return
# We defer the call to manage_addERP5Site via ZServer.PubCore because: # We defer the call to manage_addERP5Site via TimerService because:
# - we use ZPublisher so that get_request() works # - we use ZPublisher so that get_request() works
# (see new_publish in Localizer.patches) # (see Localizer patch)
# - we want errors to be logged correctly # - we want errors to be logged correctly
# (see Zope2.zpublisher_exception_hook in Zope2.App.startup) # (see Zope2.zpublisher_exception_hook in Zope2.App.startup)
import inspect, time import inspect, sys, time
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from cStringIO import StringIO from App.ZApplication import ZApplicationWrapper
from Products.ZMySQLDA.db import DB, OperationalError from Products.ZMySQLDA.db import DB, OperationalError
from ZPublisher import HTTPRequest, HTTPResponse def addERP5Site(REQUEST):
from ZServer.PubCore import handle
def addERP5Site():
default_kw = inspect.getcallargs(manage_addERP5Site, None, '') default_kw = inspect.getcallargs(manage_addERP5Site, None, '')
db = (kw.get('erp5_sql_connection_string') or db = (kw.get('erp5_sql_connection_string') or
default_kw['erp5_sql_connection_string']) default_kw['erp5_sql_connection_string'])
...@@ -2459,15 +2457,18 @@ def initialize(self): ...@@ -2459,15 +2457,18 @@ def initialize(self):
try: try:
with DB(db).lock(): with DB(db).lock():
transaction.begin() transaction.begin()
app = request['PARENTS'][0] = request['PARENTS'][0]() app = REQUEST['PARENTS'][0]
if isinstance(app, ZApplicationWrapper):
# BBB: With ZServer, it is not loaded yet.
app = REQUEST['PARENTS'][0] = app()
for _ in app.objectIds(meta_type): for _ in app.objectIds(meta_type):
return return
uf = app.acl_users uf = app.acl_users
user = uf.getUser(kw['owner']) user = uf.getUser(kw['owner'])
if not user.has_role('Manager'): if not user.has_role('Manager'):
response.unauthorized() REQUEST.RESPONSE.unauthorized()
newSecurityManager(None, user.__of__(uf)) newSecurityManager(None, user.__of__(uf))
manage_addERP5Site(app.__of__(RequestContainer(REQUEST=request)), manage_addERP5Site(app.__of__(RequestContainer(REQUEST=REQUEST)),
**{k: kw.get(k, v) for k, v in default_kw.iteritems() **{k: kw.get(k, v) for k, v in default_kw.iteritems()
if isinstance(v, str)}) if isinstance(v, str)})
transaction.get().note('Created ' + meta_type) transaction.get().note('Created ' + meta_type)
...@@ -2484,11 +2485,19 @@ def initialize(self): ...@@ -2484,11 +2485,19 @@ def initialize(self):
'MySQL error while trying to create ERP5 site. Retrying...', 'MySQL error while trying to create ERP5 site. Retrying...',
error=1) error=1)
time.sleep(5) time.sleep(5)
response = HTTPResponse.HTTPResponse(stdout=StringIO()) try:
response._finish = lambda: None TimerServer = sys.modules['Products.TimerService.timerserver.TimerServer']
Please register or sign in to reply
request = HTTPRequest.HTTPRequest( except KeyError:
StringIO(), dict(REQUEST_METHOD='GET', SERVER_URL=''), response) try: # BBB
request.traverse = lambda *args, **kw: addERP5Site TimerServer = sys.modules['timerserver.TimerServer']
handle('Zope2', request, response) except KeyError:
# There's no point installing ERP5 automatically
# if there's no timer service configured.
return
TimerRequest = TimerServer.TimerRequest
def traverse(*args, **kw):
del TimerRequest.traverse
return addERP5Site
TimerRequest.traverse = traverse
AppInitializer.initialize = initialize AppInitializer.initialize = initialize
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment