Commit 8d935010 authored by Kevin Deldycke's avatar Kevin Deldycke

Second patch

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11928 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b1d3757c
......@@ -3,7 +3,7 @@
# Authors: Nik Kim <fafhrd@legco.biz>
__version__ = '$Revision: 1.3 $'[11:-2]
import sys, time
import sys, time, threading
from DateTime import DateTime
from Globals import InitializeClass
from OFS.SimpleItem import SimpleItem
......@@ -16,6 +16,8 @@ from Products.PageTemplates.PageTemplateFile import PageTemplateFile
current_version = 1
processing_lock = threading.Lock()
class TimerService(SimpleItem):
""" timer service, all objects that wants timer
event subscribe here """
......@@ -49,23 +51,31 @@ class TimerService(SimpleItem):
def process_timer(self, interval):
""" """
# Try to acquire a lock, to make sure we only run one processing at a
# time, and abort if another processing is currently running
acquired = processing_lock.acquire(0)
if not acquired:
return
subscriptions = [self.unrestrictedTraverse(path)
for path in self._subscribers]
tick = time.time()
# prev_tick = tick - interval
# next_tick = tick + interval
prev_tick = tick - interval
next_tick = tick + interval
# LOG('TimerService', INFO, 'Ttimer tick at %s\n'%time.ctime(tick))
for subscriber in subscriptions:
try:
# subscriber.process_timer(
# interval, DateTime(tick), DateTime(prev_tick), DateTime(next_tick))
subscriber.process_timer(tick, interval)
subscriber.process_timer(
interval, DateTime(tick), DateTime(prev_tick), DateTime(next_tick))
except:
LOG('TimerService', ERROR, 'Process timer error', error = sys.exc_info())
# When processing is done, release the lock
processing_lock.release()
def subscribe(self, ob):
""" """
path = '/'.join(ob.getPhysicalPath())
......@@ -103,8 +113,6 @@ class TimerService(SimpleItem):
""" """
subs = self.lisSubscriptions()
#LOG('asdd',INFO,subs)
remove_list = [subs[n] for n in [int(n) for n in no]]
for sub in remove_list:
......
......@@ -6,10 +6,7 @@ __version__ = 'TimerServer for Zope 0.1'
import traceback
import thread
import sys, os, errno, time, socket
import ZPublisher.Client
from StringIO import StringIO
from zLOG import LOG, INFO
......@@ -20,7 +17,7 @@ from ZPublisher.HTTPRequest import HTTPRequest
from ZPublisher import Client
class TimerServer:
def __init__(self, module, interval=5):
def __init__(self, module, interval=600):
self.module = module
self.interval = interval
......
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