[Zope-CVS] CVS: Products/Scheduler - Scheduler.py:1.15
Chris McDonough
chrism@zope.com
Mon, 2 Jun 2003 16:39:10 -0400
Update of /cvs-repository/Products/Scheduler
In directory cvs.zope.org:/tmp/cvs-serv4446
Modified Files:
Scheduler.py
Log Message:
Change getPendingTasks API to return taskid.
Add consistency checks.
=== Products/Scheduler/Scheduler.py 1.14 => 1.15 ===
--- Products/Scheduler/Scheduler.py:1.14 Mon May 19 11:17:44 2003
+++ Products/Scheduler/Scheduler.py Mon Jun 2 16:38:39 2003
@@ -187,8 +187,7 @@
'interface, an integer, or a float. %s is not a valid '
'value.' % event)
- for this_time, this_task in self.getPendingTasks(t):
- taskid = this_task.taskid
+ for this_time, this_task, taskid in self.getPendingTasks(t):
self.deschedule(taskid) # deschedule the task
try:
this_task = this_task.__of__(self)
@@ -239,7 +238,7 @@
for taskid in taskid_list:
task = self.tasks.get(taskid)
task = aq_base(task).__of__(self)
- l.append((t, task))
+ l.append((t, task, taskid))
return l
security.declareProtected(VIEW_SCHEDULE_PERM, 'getPendingTaskInfo')
@@ -248,10 +247,10 @@
Return a sequence of mappings for use by UI.
"""
l = []
- for key, task in self.getPendingTasks(when):
+ for key, task, taskid in self.getPendingTasks(when):
d = { 'when':task.getTime(), 'info':task.getInfo(),
'description':task.getDescription(),
- 'taskid':task.taskid }
+ 'taskid':taskid }
l.append((key, d))
return l
@@ -280,6 +279,45 @@
l.remove(taskid)
self.times[time] = l
+ security.declareProtected(CHANGE_SCHEDULE_PERM, 'checkConsistency')
+ def checkConsistency(self):
+ """ """
+ l = []
+
+ # check task id consistency
+ timelist = self.times.items(None, sys.maxint - 1)
+
+ for t, taskid_list in timelist:
+ for taskid in taskid_list:
+ task = self.tasks.get(taskid)
+ if hasattr(task, 'taskid'):
+ if task.taskid != taskid:
+ l.append(
+ ('Task registered under taskid "%s" has taskid '
+ 'attribute "%s"' % (taskid, task.taskid)
+ ))
+ else:
+ l.append('Task registered under taskid "%s" has no taskid')
+
+ # check BTree consistency
+ from cStringIO import StringIO
+ io = StringIO()
+ import traceback
+ from BTrees.check import check
+ for tree in (self.tasks, self.times):
+ try:
+ check(aq_base(tree))
+ except:
+ traceback.print_exc(io)
+ io.seek(0)
+ s = io.read()
+ if s:
+ l.append(s)
+
+ if l:
+ return '\n'.append(l)
+ return 'OK'
+
security.declareProtected(CHANGE_SCHEDULE_PERM, 'manage_scheduleTask')
def manage_scheduleTask(self, description, when, path, interval,
max_age, max_retries, retry_backoff_time,
@@ -360,6 +398,8 @@
self._setObject(id, ob)
if REQUEST is not None:
return self.manage_main(self, REQUEST, update_menu=1)
+
+
Globals.InitializeClass(Scheduler)
Globals.InitializeClass(Task)