@@ -197,16 +197,28 @@ def simulate(self, cmds):
197197 return { 'simulation' : simulation , 'seconds' : seconds }
198198
199199
200- def submit (self , cmds , name = 'UnNamed' , queue = True ):
200+ def submit (self , cmds , name = 'UnNamed' , queue = True , timeout = 0 , deadline = None ):
201201 """Submit scan to scan server for execution
202202
203203 :param cmds: List of commands,
204204 :class:`~scan.commands.commandsequence.CommandSequence`
205205 or text with raw XML format.
206206 :param name: Name of scan
207207 :param queue: Submit to scan server queue, or execute as soon as possible?
208+ :param timeout: Timeout in seconds after which scan will self-abort
209+ :param deadline: Execution deadline in "yyyy-MM-dd HH:mm:ss" format when scan will self-abort
208210
209211 :return: ID of submitted scan
212+
213+ By default, a submitted scan will be queued.
214+ One scan is then executed at a time, in order of submission.
215+ Each scan is allowed to run until all its commands complete.
216+
217+ The 'queue' parameter allows submitting scans for immediate execution,
218+ i.e. in parallel to the queued commands.
219+
220+ Either the 'timeout' or the 'deadline' might be used to limit
221+ the execution time.
210222
211223 Examples::
212224
@@ -219,20 +231,20 @@ def submit(self, cmds, name='UnNamed', queue=True):
219231 """
220232 quoted_name = quote (name , '' )
221233 if isinstance (cmds , str ):
222- result = self .__submitScanXML (cmds , quoted_name , queue )
234+ result = self .__submitScanXML (cmds , quoted_name , queue , timeout , deadline )
223235 elif isinstance (cmds , CommandSequence ):
224- result = self .__submitScanSequence (cmds , quoted_name , queue )
236+ result = self .__submitScanSequence (cmds , quoted_name , queue , timeout , deadline )
225237 else :
226238 # Warp list, tuple, other iterable
227- result = self .__submitScanSequence (CommandSequence (cmds ), quoted_name , queue )
239+ result = self .__submitScanSequence (CommandSequence (cmds ), quoted_name , queue , timeout , deadline )
228240
229241 xml = ET .fromstring (result )
230242 if xml .tag != 'id' :
231243 raise Exception ("Expected scan <id>, got <%s>" % xml .tag )
232244 return int (xml .text )
233245
234246
235- def __submitScanXML (self , scanXML , scanName , queue = True ):
247+ def __submitScanXML (self , scanXML , scanName , queue = True , timeout = 0 , deadline = None ):
236248 """Submit scan in raw XML-form.
237249
238250 Using POST {BaseURL}/scan/{scanName}
@@ -241,6 +253,8 @@ def __submitScanXML(self, scanXML, scanName, queue=True):
241253 :param scanXML: The XML content of your new scan
242254 :param scanName: The name you want to give the new scan
243255 :param queue: Submit to scan server queue, or execute as soon as possible?
256+ :param timeout: Timeout in seconds after which scan will self-abort
257+ :param deadline: Execution deadline in "yyyy-MM-dd HH:mm:ss" format when scan will self-abort
244258
245259 :return: Raw XML for scan ID
246260
@@ -251,22 +265,33 @@ def __submitScanXML(self, scanXML, scanName, queue=True):
251265 >>> id = ssc.__submitScanXML(scanXML='<commands><comment><address>0</address><text>Successfully adding a new scan!</text></comment></commands>',scanName='1stScan')
252266 """
253267 url = self .__baseURL + "/scan/" + scanName
268+
269+ flags = False
254270 if not queue :
255271 url = url + "?queue=false"
272+ flags = True
273+ if timeout > 0 :
274+ url = url + ("&" if flags else "?" ) + "timeout=" + str (timeout )
275+ flags = True
276+ if deadline is not None and deadline != "0000-00-00 00:00:00" :
277+ url = url + ("&" if flags else "?" ) + "deadline=" + quote (deadline )
278+
256279 r = perform_request (url , 'POST' , scanXML )
257280 return r
258281
259282
260- def __submitScanSequence (self , cmdSeq , scanName , queue = True ):
283+ def __submitScanSequence (self , cmdSeq , scanName , queue = True , timeout = 0 , deadline = None ):
261284 """Submit a CommandSequence
262285
263286 :param cmdSeq: :class:`scan.commands.commandsequence.CommandSequence`
264287 :param scanName: The name needed to give the new scan
265288 :param queue: Submit to scan server queue, or execute as soon as possible?
289+ :param timeout: Timeout in seconds after which scan will self-abort
290+ :param deadline: Execution deadline in "yyyy-MM-dd HH:mm:ss" format when scan will self-abort
266291
267292 :return: Raw XML for scan ID
268293 """
269- return self .__submitScanXML (cmdSeq .genSCN (),scanName , queue )
294+ return self .__submitScanXML (cmdSeq .genSCN (),scanName , queue , timeout , deadline )
270295
271296
272297 def scanInfos (self , timeout = 20 ):
0 commit comments