Package Jobber :: Module interfaces
[hide private]
[frames] | no frames]

Source Code for Module Jobber.interfaces

  1  ########################################################################### 
  2  # 
  3  # This program is part of Zenoss Core, an open source monitoring platform. 
  4  # Copyright (C) 2009, Zenoss Inc. 
  5  # 
  6  # This program is free software; you can redistribute it and/or modify it 
  7  # under the terms of the GNU General Public License version 2 as published by 
  8  # the Free Software Foundation. 
  9  # 
 10  # For complete information please visit: http://www.zenoss.com/oss/ 
 11  # 
 12  ########################################################################### 
 13   
 14  from zope.interface import Interface 
 15   
16 -class IJob(Interface):
17 """ 18 Persistent object that contains the entry-point function for running a job. 19 """
20 - def start():
21 """ 22 Begins the job-running process. Does setup, then calls self.run(). 23 """
24 - def run():
25 """ 26 Contains all job-specific code. This will be overridden in subclasses 27 to provide the ability to run different kinds of jobs. 28 """
29 - def finished(results):
30 """ 31 Called when the job is finished. 32 """
33 - def interrupt(why):
34 """ 35 Halt the running of the job. If necessary, send signals to any 36 subprocesses that are involved in job running. 37 """
38 - def update(msg):
39 """ 40 Set the current status of the running job to C{msg}. 41 """
42 - def getStatus():
43 """ 44 Get the L{IJobStatus} associated with this job. 45 """
46
47 -class IJobStatus(Interface):
48 """ 49 Contains interesting information about a job, including state, start and 50 finish times, and log file. 51 """
52 - def getJob():
53 """ 54 Return the IJob associated with this status object. 55 """
56 - def getTimes():
57 """ 58 Returns a (start, end) tuple, indicating when the Job started and 59 finished. If the Job is still running, end will be None. 60 """
61 - def getLog():
62 """ 63 Return the ILogFile that contains the job output. 64 """
65 - def isFinished():
66 """ 67 Return a boolean indicating whether or not the job has finished. 68 """
69 - def waitUntilFinished():
70 """ 71 Return a Deferred that will fire when the IJob finishes. If the IJob 72 has finished, this Deferred will fire right away. 73 """
74 - def getResult():
75 """ 76 Return a constant describing the results of the job, from jobs.status: 77 SUCCESS or FAILURE. 78 """
79
80 -class IJobManager(Interface):
81 """ 82 Provides a hub for the job subsystem. Can be queried to find the status of 83 running or previous jobs. Jobs are created from here. 84 """
85 - def addJob(klass):
86 """ 87 Create an instance of C{klass}, which must implement L{IJob}. 88 89 @return: A Job instance. 90 @rtype: IJob 91 """
92 - def getJobStatus(job):
93 """ 94 Return the IJobStatus for a given IJob or job id. 95 """
96 - def getUnfinishedJobs():
97 """ 98 Return IJobStatus objects that have yet to finish. 99 """
100 - def getRunningJobs():
101 """ 102 Return IJobStatus objects that have started and have yet to finish. 103 """
104 - def getPendingJobs():
105 """ 106 Return IJobStatus objects that have yet to start. 107 """
108
109 -class IJobLogFile(Interface):
110 """ 111 Job output of any kind. 112 """
113 - def write(data):
114 """ 115 Write C{data} to the Log. 116 """
117 - def finish():
118 """ 119 No further data will be added to the log file, so close it and notify 120 anyone who cares. 121 """
122 - def subscribe(subscriber, catchup=False):
123 """ 124 Register to receive output as data is added to the log. If catchup is 125 True, log contents up to that point will be returned immediately to the 126 receiver. 127 128 @param subscriber: The receiver of data as it comes in 129 @type subscriber: file-like 130 """
131 - def unsubscribe(subscriber):
132 """ 133 Remove a previously registered subscriber. 134 """
135 - def getStatus():
136 """ 137 Return the IJobStatus that owns this log. 138 """
139 - def getFilename():
140 """ 141 Return the filename of the file on disk containing the log data. 142 """
143 - def isFinished():
144 """ 145 Return a boolean indicating whether or not the log has finished. 146 """
147 - def waitUntilFinished():
148 """ 149 Return a Deferred that will fire when the log finishes. If the log has 150 finished, this Deferred will fire right away. 151 """
152