Commit 984eddfd authored by Vincent Pelletier's avatar Vincent Pelletier

Acquire tick lock in non-blocking mode, similarly to...

Acquire tick lock in non-blocking mode, similarly to CMFActivity/ActivityTool.py: this allows a process_timer call to return quickly when previous tick is still processing. This prevents portal_alarms from using threads to just wait for one tic call to complete.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@23709 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 684cfb56
...@@ -200,21 +200,23 @@ class AlarmTool(BaseTool): ...@@ -200,21 +200,23 @@ class AlarmTool(BaseTool):
This method is called by TimerService in the interval given This method is called by TimerService in the interval given
in zope.conf. The Default is every 5 seconds. in zope.conf. The Default is every 5 seconds.
""" """
# only start when we are the alarmNode acquired = last_tic_lock.acquire(0)
alarmNode = self.getAlarmNode() if not acquired:
current_node = self.getCurrentNode() return
if alarmNode == '': try:
self.setAlarmNode(current_node) # only start when we are the alarmNode
alarmNode = current_node alarmNode = self.getAlarmNode()
if alarmNode == current_node: current_node = self.getCurrentNode()
global last_tic if alarmNode == '':
last_tic_lock.acquire(1) self.setAlarmNode(current_node)
try: alarmNode = current_node
if alarmNode == current_node:
global last_tic
if tick.timeTime() - last_tic >= self.interval: if tick.timeTime() - last_tic >= self.interval:
self.tic() self.tic()
last_tic = tick.timeTime() last_tic = tick.timeTime()
finally: finally:
last_tic_lock.release() last_tic_lock.release()
def getCurrentNode(self): def getCurrentNode(self):
""" Return current node in form ip:port """ """ Return current node in form ip:port """
......
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