[Zope3-Users] Scheduler package usage
Thierry Florac
thierry.florac at onf.fr
Tue Nov 21 07:04:36 EST 2006
Hi,
I'm trying to use the "scheduler" package available from Zope3's CVS to
handle a set of regular and automatic tasks in my Zope-3.3 setup (using
Twisted).
My code is as follows :
manager.py::
def fire_alerts():
# Handle exception because alert can be fired
# before utilities are registered
try:
query = zapi.getUtility(IQuery)
query_index = ('Catalog','alert')
query_param = Le(query_index, datetime.now())
alerts = query.searchResults(query_param)
for alert in alerts:
alert.alert()
except:
print " >>> AlertsManager : an error occurred !"
class AlertsManager(CronTask):
"""Alerts are defined as CronTasks launched every 5
minutes"""
implements(IAlertsManager)
def __init__(self, *args, **kw):
super(AlertsManager,self).__init__(callable=fire_alerts,
\
minute=(5,10,15,20,25,30,35,40,45,46,47,48,49,50,55,))
configure.zcml::
<utility
name="AlertsManager"
factory=".manager.AlertsManager"
provides="scheduler.interfaces.ITask" />
Adding a few "prints" show that AlertsManager is well instanciated and
that the defined alert is called only once if the "start" method is
overriden with "now=True" ; but after that, even if the alert seems to
be rescheduled at the correct time, the corresponding task is not called
anymore.
Another last question : are transaction handled "normally" and
"transparently" as are other Zope3 transactions, or should I have to
handle them specifically when the requested task can modify data ??
Any help or advise would be greatly appreciated...
Thierry Florac
--
Chef de projet intranet/internet
Office National des Forêts - Département Informatique
2, Avenue de Saint-Mandé
75570 PARIS Cedex 12
Mél : thierry.florac at onf.fr
Tél. : +33 01.40.19.59.64
Fax. : +33 01.40.19.59.85
More information about the Zope3-users
mailing list