Job: + whenStarted, whenFinished callbacks; remove transport/httpput.py

git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1913 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2007-08-14 07:32:38 +00:00
parent 1e6eb9e4f6
commit 5348071d34
5 changed files with 18 additions and 7 deletions

View file

@ -28,7 +28,7 @@ from loops.agent.interfaces import IAgent
from loops.agent.config import Configurator
from loops.agent.crawl import filesystem
from loops.agent.schedule import Scheduler, Stopper
from loops.agent.transport import httpput
from loops.agent.transport import base
crawlTypes = dict(
@ -36,7 +36,7 @@ crawlTypes = dict(
)
transportTypes = dict(
httpput=httpput.Transporter,
httpput=base.Transporter,
)

View file

@ -64,8 +64,15 @@ class IScheduledJob(Interface):
startTime = Attribute('Date/time at which the job should be executed.')
params = Attribute('Mapping with key/value pairs to be used by '
'the ``execute()`` method.')
repeat = Attribute('Number of seconds after which the job should be '
'rescheduled. Do not repeat if 0.')
successors = Attribute('Jobs to execute immediately after this '
'one has been finished.')
'one has been finished.')
whenStarted = Attribute('A callable with no arguments that will '
'be called when the job has started.')
whenfinished = Attribute('A callable with one argument, the '
'result of running the job, that will be called when '
'the job has finished.')
def execute():
""" Execute the job.

View file

@ -59,6 +59,9 @@ class Job(object):
scheduler = None
whenStarted = lambda self: None
whenFinished = lambda self, result: None
def __init__(self, **params):
self.startTime = 0
self.params = params
@ -76,6 +79,7 @@ class Job(object):
def run(self):
d = self.execute()
d.addCallback(self.finishRun)
self.whenStarted()
# TODO: logging
def finishRun(self, result):
@ -86,6 +90,7 @@ class Job(object):
job.params['result'] = result
#job.run()
self.scheduler.schedule(job)
self.whenFinished(result)
# TODO: logging
# reschedule if necessary
if self.repeat:

View file

@ -33,8 +33,7 @@ from twisted.web import http
class RequestHandler(http.Request):
def process(self):
print '***', self.uri
print '***', self.content.read()
print '***', repr(self.content.read())
if self.method in ('GET', 'POST'):
self.write('<h1>Hello World</h1>')
self.write('<p>dir(self): %s</p>' % dir(self))

View file

@ -81,8 +81,8 @@ class Transporter(object):
data.close()
else:
text = data
# TODO: encode text
# TODO: set headers, esp Content-Type
# TODO: encode text (?)
# TODO: set headers: Content-Type, Authorization, User-Agent
path = resource.path
app = resource.application
deferreds = []