[Checkins] SVN: zc.async/trunk/src/zc/async/ - merge jackie-callable-on-job branch to trunk so having a job whose callable
John Murphy
jackie at zope.com
Wed Nov 11 09:50:01 EST 2009
Log message for revision 105584:
- merge jackie-callable-on-job branch to trunk so having a job whose callable
is a method on the job doesn't cause a hang
svn merge svn+ssh://svn.zope.org/repos/main/zc.async/branches/jackie-callable-on-job -r105572:105573 .
Changed:
U zc.async/trunk/src/zc/async/CHANGES.txt
U zc.async/trunk/src/zc/async/job.py
U zc.async/trunk/src/zc/async/job.txt
-=-
Modified: zc.async/trunk/src/zc/async/CHANGES.txt
===================================================================
--- zc.async/trunk/src/zc/async/CHANGES.txt 2009-11-11 14:40:08 UTC (rev 105583)
+++ zc.async/trunk/src/zc/async/CHANGES.txt 2009-11-11 14:50:00 UTC (rev 105584)
@@ -23,6 +23,9 @@
- Tests pass on Python 2.6
+- The callable of a zc.async.job.Job (or one of its subclasses) can be a method
+ on the Job itself.
+
1.5.2 (2009-07-22)
==================
Modified: zc.async/trunk/src/zc/async/job.py
===================================================================
--- zc.async/trunk/src/zc/async/job.py 2009-11-11 14:40:08 UTC (rev 105583)
+++ zc.async/trunk/src/zc/async/job.py 2009-11-11 14:50:00 UTC (rev 105584)
@@ -431,7 +431,7 @@
res = _status_mapping[self._status_id]
if res == zc.async.interfaces.NEW:
ob = self.parent
- while (ob is not None and
+ while (ob is not None and ob is not self and
zc.async.interfaces.IJob.providedBy(ob)):
ob = ob.parent
if zc.async.interfaces.IAgent.providedBy(ob):
Modified: zc.async/trunk/src/zc/async/job.txt
===================================================================
--- zc.async/trunk/src/zc/async/job.txt 2009-11-11 14:40:08 UTC (rev 105583)
+++ zc.async/trunk/src/zc/async/job.txt 2009-11-11 14:50:00 UTC (rev 105584)
@@ -1636,6 +1636,39 @@
>>> time.sleep = old_sleep # probably put in test tearDown
+
+Subclassing Job
+===============
+
+You can subclass zc.async.job.Job for your own purposes.
+
+ >>> class SpecialJob(zc.async.job.Job):
+ ... def __init__(self, *args, **kwargs):
+ ... super(SpecialJob, self).__init__(*args, **kwargs)
+
+ >>> special_job = SpecialJob(multiply, 3, 4)
+ >>> special_job.status
+ u'new-status'
+ >>> special_job.callable(*special_job.args)
+ 12
+
+You may even decide to have your callable be an attribute on your job.
+
+ >>> class MultiplyJob(zc.async.job.Job):
+ ... def __init__(self, arg1, arg2):
+ ... super(MultiplyJob, self).__init__(self.do_multiply)
+ ... self.arg1 = arg1
+ ... self.arg2 = arg2
+ ... def do_multiply(self):
+ ... return self.arg1 * self.arg2
+
+ >>> multiply_job = MultiplyJob(5, 6)
+ >>> multiply_job.status
+ u'new-status'
+ >>> multiply_job.callable()
+ 30
+
+
=========
Footnotes
=========
More information about the checkins
mailing list