Commit 005a4832 authored by Kevin Deldycke's avatar Kevin Deldycke

Last patch (see http://svn.erp5.org?rev=10468&view=rev for details):

 * make TimerService.process_timer public to shut up VerboseSecurity messages,
 * use finally to release the lock in TimerService.process_timer,
 * reraise all exceptions from suscriber.process_timer.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11931 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 83217de3
...@@ -26,7 +26,8 @@ class TimerService(SimpleItem): ...@@ -26,7 +26,8 @@ class TimerService(SimpleItem):
title = 'TimerService' title = 'TimerService'
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectPublic()
icon = 'misc_/TimerService/timer_icon.gif' icon = 'misc_/TimerService/timer_icon.gif'
max_size = 0 max_size = 0
...@@ -48,39 +49,43 @@ class TimerService(SimpleItem): ...@@ -48,39 +49,43 @@ class TimerService(SimpleItem):
""" """ """ """
self._subscribers = [] self._subscribers = []
self._version = 1 self._version = 1
security.declarePublic('process_timer')
def process_timer(self, interval): def process_timer(self, interval):
""" """ """ """
# Try to acquire a lock, to make sure we only run one processing at a # Try to acquire a lock, to make sure we only run one processing at a
# time, and abort if another processing is currently running # time, and abort if another processing is currently running
acquired = processing_lock.acquire(0) acquired = processing_lock.acquire(0)
if not acquired: if not acquired:
return return
# Don't let TimerService crash when the ERP5Site is not yet existing.
# This case append when we create a new Portal: At that step Timer Service start
# to 'ping' the portal before the zope transaction in which the portal is
# created is commited.
subscriptions = []
try: try:
subscriptions = [self.unrestrictedTraverse(path) # Don't let TimerService crash when the ERP5Site is not yet existing.
for path in self._subscribers] # This case append when we create a new Portal: At that step Timer
except KeyError: # Service start to 'ping' the portal before the zope transaction in
pass # which the portal is created is commited.
subscriptions = []
tick = time.time() try:
prev_tick = tick - interval subscriptions = [self.unrestrictedTraverse(path)
next_tick = tick + interval for path in self._subscribers]
except KeyError:
for subscriber in subscriptions: pass
try:
subscriber.process_timer( tick = time.time()
interval, DateTime(tick), DateTime(prev_tick), DateTime(next_tick)) prev_tick = tick - interval
except: next_tick = tick + interval
LOG('TimerService', ERROR, 'Process timer error', error = sys.exc_info())
for subscriber in subscriptions:
# When processing is done, release the lock try:
processing_lock.release() subscriber.process_timer(
interval, DateTime(tick),
DateTime(prev_tick), DateTime(next_tick))
except:
LOG('TimerService', ERROR, 'Process timer error',
error = sys.exc_info())
raise
finally:
# When processing is done, release the lock
processing_lock.release()
def subscribe(self, ob): def subscribe(self, ob):
""" """ """ """
...@@ -91,6 +96,8 @@ class TimerService(SimpleItem): ...@@ -91,6 +96,8 @@ class TimerService(SimpleItem):
subscribers.append(path) subscribers.append(path)
self._subscribers = subscribers self._subscribers = subscribers
security.declareProtected(
Permissions.view_management_screens, 'unsubscribeByPath')
def unsubscribeByPath(self, path): def unsubscribeByPath(self, path):
subscribers = self._subscribers subscribers = self._subscribers
if path in subscribers: if path in subscribers:
...@@ -111,7 +118,9 @@ class TimerService(SimpleItem): ...@@ -111,7 +118,9 @@ class TimerService(SimpleItem):
def lisSubscriptions(self): def lisSubscriptions(self):
""" """ """ """
return self._subscribers return self._subscribers
security.declareProtected(
Permissions.view_management_screens, 'manage_removeSubscriptions')
def manage_removeSubscriptions(self, no, REQUEST=None): def manage_removeSubscriptions(self, no, REQUEST=None):
""" """ """ """
subs = self.lisSubscriptions() subs = self.lisSubscriptions()
......
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