[Zope-CVS] CVS: Products/Scheduler - Task.py:1.4

Martijn Pieters cvs-admin at zope.org
Wed Oct 29 17:09:09 EST 2003


Update of /cvs-repository/Products/Scheduler
In directory cvs.zope.org:/tmp/cvs-serv6221

Modified Files:
	Task.py 
Log Message:
Augment tasks to support arbitrary positional and keyword arguments for the
task. If no arguments are provided when creating the task, the task falls
back to the old behaviour of using REQUEST.args and REQUEST.


=== Products/Scheduler/Task.py 1.3 => 1.4 ===
--- Products/Scheduler/Task.py:1.3	Mon Jul  7 17:31:50 2003
+++ Products/Scheduler/Task.py	Wed Oct 29 17:09:09 2003
@@ -36,10 +36,14 @@
     security.declareObjectPublic()
     security.setDefaultAccess("allow")
 
+    args = None
+    kw = None
+
     __implements__ = IScheduledEvent
 
     def __init__(self, description, when, path, interval=None, max_age=600,
-                 max_retries=5, retry_backoff_time=60, filter_data=None):
+                 max_retries=5, retry_backoff_time=60, filter_data=None,
+                 args=(), kw=None):
         self.description = description
         self.when = when
         self.path = path
@@ -50,8 +54,16 @@
         self.retries = 0
         self.filter_data = filter_data
 
+        if args:
+            self.args = args
+
+        if kw is not None:
+            self.kw = {}
+            self.kw.update(kw)
+
     def __call__(self):
-        """Run the method on self.path with REQUEST['args'].
+        """Run the method on self.path with arguments taken from self.args and
+           self.kw or REQUEST.args and REQUEST if the first two are empty.
 
         On failure we reschedule, iff max_age and max_retries have not been
         exceeded."""
@@ -150,9 +162,13 @@
         return self.filter_data
 
     def _runMethod(self, request):
-        args = getattr(request, 'args', {})
+        args = self.args or ()
+        kw = self.kw or {}
+        if not (args or kw):
+            args = request.args
+            kw = request
         method = self.restrictedTraverse(self.path)
-        result = mapply(method, args, request,
+        result = mapply(method, args, kw,
                         call_object, 1,
                         missing_name,
                         dont_publish_class,
@@ -168,7 +184,8 @@
                               max_age=self.max_age,
                               max_retries=self.max_retries,
                               retry_backoff_time=self.retry_backoff_time,
-                              filter_data=self.filter_data)
+                              filter_data=self.filter_data,
+                              args=self.args, kw=self.kw)
 
 class InconsistentSchedulerMarkerTask(Implicit):
     """ A task implementation which is operated against when there




More information about the Zope-CVS mailing list