Jobs should subclass Products.Jobber.jobs.Job. At a minimum, a Job must implement its own run() method, which should perform the actions specific to the job and call back to the finished() method reporting success or failure.
Example 7.1. A Job that cleans up the history table in the events database
from Products.Jobber.jobs import Job
from Products.Jobber.status import SUCCESS, FAILURE
class CleanHistoryJob(Job):
"""
Delete all events of a certain age from the
history table.
"""
def __init__(self, agedDays=7):
self.agedDays = agedDays
super(CleanHistoryJob, self).__init__()
def run(self, r):
zem = self.dmd.ZenEventManager
try:
zem.manage_deleteHistoricalEvents(
agedDays=self.agedDays)
except:
self.finished(FAILURE)
else:
self.finished(SUCCESS)