[Checkins] SVN: zc.async/branches/jackie-callable-on-job/src/zc/async/job. - subclassing zc.async.job.Job works when the job's callable is on the job
John Murphy
jackie at zope.com
Tue Nov 10 13:53:49 EST 2009
Log message for revision 105573:
- subclassing zc.async.job.Job works when the job's callable is on the job
itself
Changed:
U zc.async/branches/jackie-callable-on-job/src/zc/async/job.py
U zc.async/branches/jackie-callable-on-job/src/zc/async/job.txt
-=-
Modified: zc.async/branches/jackie-callable-on-job/src/zc/async/job.py
===================================================================
--- zc.async/branches/jackie-callable-on-job/src/zc/async/job.py 2009-11-10 17:20:10 UTC (rev 105572)
+++ zc.async/branches/jackie-callable-on-job/src/zc/async/job.py 2009-11-10 18:53:48 UTC (rev 105573)
@@ -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/branches/jackie-callable-on-job/src/zc/async/job.txt
===================================================================
--- zc.async/branches/jackie-callable-on-job/src/zc/async/job.txt 2009-11-10 17:20:10 UTC (rev 105572)
+++ zc.async/branches/jackie-callable-on-job/src/zc/async/job.txt 2009-11-10 18:53:48 UTC (rev 105573)
@@ -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