Commit 635ea405 authored by Bryton Lacquement's avatar Bryton Lacquement 🚪

TimerService: make timerserver compatible with WSGI

At the same time, timerserver is no longer distributed as an egg.
parent dc664528
......@@ -9,7 +9,7 @@ from tempfile import TemporaryFile
import time
from urllib import quote
from waitress import serve
from waitress.server import create_server
import ZConfig
import Zope2
from Zope2.Startup.run import make_wsgi_app
......@@ -140,6 +140,8 @@ def app_wrapper(large_file_threshold, use_webdav):
def runwsgi():
global server
parser = argparse.ArgumentParser()
parser.add_argument('-w', '--webdav', action='store_true')
parser.add_argument('address', help='<ip>:<port>')
......@@ -152,11 +154,10 @@ def runwsgi():
make_wsgi_app({}, zope_conf=args.zope_conf)
z2log = logging.getLogger("access")
serve(
server = create_server(
TransLogger(app_wrapper(conf.large_file_threshold, args.webdav),
logger=z2log),
logger=logging.getLogger("access")),
listen=args.address,
threads=conf.zserver_threads,
)
server.run()
......@@ -8,10 +8,10 @@ import traceback
import thread
import re
import sys, os, errno, time, socket
from functools import partial
from StringIO import StringIO
from zLOG import LOG, INFO
from ZServer.PubCore import handle
from ZPublisher.BaseRequest import BaseRequest
from ZPublisher.BaseResponse import BaseResponse
from ZPublisher.HTTPRequest import HTTPRequest
......@@ -38,21 +38,46 @@ class TimerServer:
'\tInterval: %s seconds.\n'%(time.ctime(time.time()), interval))
def run(self):
# wait until the zhttp_server exist in socket_map
# because TimerService has to be started after the Zope HTTPServer
from asyncore import socket_map
ip = port = ''
while 1:
time.sleep(5)
for k, v in socket_map.items():
if hasattr(v, 'addr'):
try:
zopewsgi = sys.modules['Products.ERP5.bin.zopewsgi']
except KeyError:
# wait until the zhttp_server exist in socket_map
# because TimerService has to be started after the Zope HTTPServer
from asyncore import socket_map
ip = port = ''
while 1:
time.sleep(5)
for k, v in socket_map.items():
if hasattr(v, 'addr'):
# see Zope/lib/python/App/ApplicationManager.py: def getServers(self)
type = str(getattr(v, '__class__', 'unknown'))
if type == 'ZServer.HTTPServer.zhttp_server':
ip, port = v.addr
break
if port:
break
if port:
break
from ZServer.PubCore import handle
else:
while 1:
time.sleep(5)
try:
server = zopewsgi.server
break
except AttributeError:
pass
ip, port = server.addr
start_response = lambda *_: None
class handle(object):
def __init__(self, module_name, request, response):
self.service = partial(zopewsgi.publish_module,
request.environ,
start_response,
_module_name=module_name,
_request=request,
_response=response)
server.add_task(self)
if ip == '0.0.0.0':
ip = socket.gethostbyname(socket.gethostname())
......@@ -99,6 +124,9 @@ class TimerServer:
class TimerResponse(BaseResponse):
after_list = ()
def _finish(self):
pass
......@@ -108,6 +136,9 @@ class TimerResponse(BaseResponse):
def _unauthorized(self):
pass
def finalize(self):
return None, None
# This is taken from ZPublisher.HTTPResponse
# I don't think it's safe to make TimerResponse a subclass of HTTPResponse,
# so I inline here the method . This is required it you want unicode page
......@@ -148,6 +179,7 @@ class TimerRequest(HTTPRequest):
env['SERVER_PORT'] = ''
env['REMOTE_ADDR'] = ''
env['GATEWAY_INTERFACE'] = 'CGI/1.1'
env['SERVER_PROTOCOL'] = 'HTTP/1.0'
env['PATH_INFO']= '/Control_Panel/timer_service/process_timer'
return env
......
#!/usr/bin/env python
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
setup(name='timerserver',
version='2.0.4',
license='GPL',
description='Timer Server for Zope',
long_description='',
author='Nikolay Kim',
author_email='fafhrd@legco.biz',
packages=['timerserver'],
zip_safe=False,
package_data={'timerserver': ['component.xml']},
)
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