...
 
Commits (3)
......@@ -2485,16 +2485,7 @@ def initialize(self):
'MySQL error while trying to create ERP5 site. Retrying...',
error=1)
time.sleep(5)
try:
TimerServer = sys.modules['Products.TimerService.timerserver.TimerServer']
except KeyError:
try: # BBB
TimerServer = sys.modules['timerserver.TimerServer']
except KeyError:
# There's no point installing ERP5 automatically
# if there's no timer service configured.
return
TimerRequest = TimerServer.TimerRequest
from Products.TimerService.timerserver.TimerServer import TimerRequest
def traverse(*args, **kw):
del TimerRequest.traverse
return addERP5Site
......
......@@ -2,11 +2,9 @@
# -*- Mode: Python; py-indent-offset: 4 -*-
# Authors: Nik Kim <fafhrd@legco.biz>
import sys
from App.ImageFile import ImageFile
from AccessControl import ModuleSecurityInfo, allow_module
from AccessControl.Permissions import view
from TimerService import TimerService, current_version
from .TimerService import TimerService, current_version
misc_ = { 'timer_icon.gif':
ImageFile('zpt/timer_icon.gif', globals())}
......@@ -28,3 +26,13 @@ def getTimerService(context):
control_panel._delObject(cp_id)
root._setObject(cp_id, timer_service)
return timer_service
try:
old = sys.modules['timerserver']
except KeyError:
pass
else: # BBB: old timerserver loaded from zope config, force use of new one
assert 'timerserver.TimerServer' not in sys.modules
from .timerserver import TimerServerFactory
old.TimerServerFactory.create = TimerServerFactory.create.__func__
del old, TimerServerFactory
# -*- coding: UTF-8 -*-
# -*- Mode: Python; py-indent-offset: 4 -*-
# Authors: Nik Kim <fafhrd@legco.biz>
__version__ = 'TimerServer for Zope 0.1'
import traceback
import thread
import re
import sys, os, errno, time, socket
import errno, logging, os, re, socket, sys, threading, time, traceback
from functools import partial
from urlparse import urlsplit
from StringIO import StringIO
from zLOG import LOG, INFO
from ZPublisher.BaseRequest import BaseRequest
from ZPublisher.BaseResponse import BaseResponse
from ZPublisher.HTTPRequest import HTTPRequest
from ZPublisher.HTTPResponse import HTTPResponse
import ZPublisher.HTTPRequest
class TimerServer:
logger = logging.getLogger('TimerServer')
class TimerServer(threading.Thread):
def __init__(self, module, interval=600):
super(TimerServer, self).__init__()
self.daemon = True
self.module = module
self.interval = interval
sync = thread.allocate_lock()
self._a = sync.acquire
self._r = sync.release
self._a()
thread.start_new_thread(self.run, ())
self._r()
LOG('ZServer', INFO,
'Timer server started at %s\n'
'\tInterval: %s seconds.\n'%(time.ctime(time.time()), interval))
self.start()
logger.info('Service initialized with interval of %s second(s).',
interval)
def run(self):
try:
......@@ -104,16 +91,7 @@ class TimerServer:
module = self.module
interval = self.interval
# minutes = time.gmtime(time.time()[4], seconds = time.gmtime(time.time()[5]
# max interval is therefore 59*60 + 59 = 208919 seconds
wait = ((time.gmtime(time.time())[4] * 60) + time.gmtime(time.time())[5]) % interval
sleep = interval - wait
if sleep > 0:
time.sleep(sleep)
LOG('ZServer', INFO, 'Timerserver ready, starting timer services.')
logger.info('Service ready.')
while 1:
time.sleep(interval)
......