[TransWarp] PROPOSAL: refactoring of peak.running.daemons
Ulrich Eck
ueck at net-labs.de
Wed Apr 16 09:24:47 EDT 2003
[snip proposal]
i've worked with Jim Fulton on a Task Schedule for Zope3
(meant to be a low-resolution Schedule e.g. once per sec/min/..)
we designed a similar system as you're implementing and i wanted
to give you a chance to look at the interfaces we defined:
In our concept there play to parts:
Schedule and Tasks
A Schedule manages tasks (Stored in a OO-BTree with
datetime as Key -> [Tasks,] as Value)
calling the process method below with a datetime causes all
Tasks that need to be processed get __call__(ed).
If a Task has an internal error, it returns another Task-object
otherwise None. When the processing is finished, the schedule
method on a Task is called to give the Task a chanche to reschedule
itself.
Interface (pre namegeddon):
class ISchedule(Interface):
"""A Task Queue with Scheduling Policy
"""
def schedule(task):
"""add a task to the Queue
"""
def unschedule(task):
"""remove a task from the Queue
"""
class IScheduleControl(Interface):
"""A Task Queue Control Interface
"""
def process(time):
"""Process due tasks
"""
def getTaskTimes():
"""Return all datetimes for scheduled Tasks
"""
class ITask(Interface):
time = Datetime(description=u"The time at which the
task should execute",
readonly=1,
required=1)
principalId = Line(description=u"The principalId that
the task should be executed as.",
readonly=1,
required=1)
description = Text(description=u"The description of the
task for task ")
def __call__():
"""Execute the task
Exceptions raised by execute will be logged.
If execution is sucessful, return None.
A task may be returned to retry work after an error.
"""
def schedule():
"""Schedule a new task
If the execution of the task is sucessful
(execute returns None),
then schedule is called to optionally (re)schedule a task.
None may be returned if no task needs to be scheduled.
This method is used to implement repeating tasks.
"""
i don't know if this scheme is suitable for what you want as well.
cheers
Ulrich Eck
More information about the PEAK
mailing list