Commit 499b61dd authored by Jérome Perrin's avatar Jérome Perrin

last_tic is a now RAM variable, to prevent unnecessary database writes.

interval can be configured with manage properties screen.
make process_timer, otherwise it's possible to pass a fake tick time and disable timers.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@9611 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent cf4ef4c4
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
############################################################################## ##############################################################################
import time import time
import threading
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from Globals import InitializeClass, DTMLFile, PersistentMapping from Globals import InitializeClass, DTMLFile, PersistentMapping
...@@ -34,7 +36,6 @@ from Products.ERP5Type.Document.Folder import Folder ...@@ -34,7 +36,6 @@ from Products.ERP5Type.Document.Folder import Folder
from Products.ERP5Type.Tool.BaseTool import BaseTool from Products.ERP5Type.Tool.BaseTool import BaseTool
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from Products.ERP5 import _dtmldir from Products.ERP5 import _dtmldir
from Products.CMFCore import CMFCorePermissions
from DateTime import DateTime from DateTime import DateTime
from zLOG import LOG, INFO from zLOG import LOG, INFO
...@@ -45,6 +46,9 @@ except ImportError: ...@@ -45,6 +46,9 @@ except ImportError:
def getTimerService(self): def getTimerService(self):
pass pass
last_tic = time.time()
last_tic_lock = threading.Lock()
class AlarmTool(BaseTool): class AlarmTool(BaseTool):
""" """
This tool manages alarms. This tool manages alarms.
...@@ -57,7 +61,6 @@ class AlarmTool(BaseTool): ...@@ -57,7 +61,6 @@ class AlarmTool(BaseTool):
id = 'portal_alarms' id = 'portal_alarms'
meta_type = 'ERP5 Alarm Tool' meta_type = 'ERP5 Alarm Tool'
portal_type = 'Alarm Tool' portal_type = 'Alarm Tool'
allowed_types = ('Supply Alarm Line',)
# Declarative Security # Declarative Security
security = ClassSecurityInfo() security = ClassSecurityInfo()
...@@ -86,8 +89,8 @@ class AlarmTool(BaseTool): ...@@ -86,8 +89,8 @@ class AlarmTool(BaseTool):
+ Folder.manage_options + Folder.manage_options
) )
_properties = ( {'id': 'interval', 'type': 'int', 'mode': 'w', }, )
interval = 60 # Default interval for alarms is 60 seconds interval = 60 # Default interval for alarms is 60 seconds
last_tic = time.time()
# API to manage alarms # API to manage alarms
# Aim of this API: # Aim of this API:
...@@ -194,13 +197,19 @@ class AlarmTool(BaseTool): ...@@ -194,13 +197,19 @@ class AlarmTool(BaseTool):
self.subscribe() self.subscribe()
BaseTool.inheritedAttribute('manage_afterAdd')(self, item, container) BaseTool.inheritedAttribute('manage_afterAdd')(self, item, container)
security.declarePrivate('process_timer')
def process_timer(self, interval, tick, prev="", next=""): def process_timer(self, interval, tick, prev="", next=""):
""" """
Call tic() every x seconds. x is defined in self.interval Call tic() every x seconds. x is defined in self.interval
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.
""" """
if tick.timeTime() - self.last_tic >= self.interval: global last_tic
last_tic_lock.acquire(1)
try:
if tick.timeTime() - last_tic >= self.interval:
self.tic() self.tic()
self.last_tic = tick.timeTime() last_tic = tick.timeTime()
finally:
last_tic_lock.release()
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