def wait(self, jobname, poll_interval=2, timeout=None, clean=False, show=None): """ Block until the job has finished. Returns a list of the result urls. :type poll_interval: int :param poll_interval: the number of seconds between job status requests. :type timeout: int or None :param timeout: if specified, the number of seconds before returning or raising a :class:`disco.JobError`. :type clean: bool :param clean: if `True`, call :meth:`Disco.clean` when the job has finished. .. deprecated:: 0.4 :type show: bool or string :param show: enables console output of job events. The default is provided by :envvar:`DISCO_EVENTS`. .. versionadded:: 0.2.3 """ if show is None: show = self.settings['DISCO_EVENTS'] event_monitor = EventMonitor(Job(name=jobname, master=self.master), format=show, poll_interval=poll_interval) start_time = time.time() try: while True: event_monitor.refresh() try: return self.check_results(jobname, start_time, timeout, poll_interval * 1000) except Continue: continue finally: if clean: self.clean(jobname) event_monitor.refresh() finally: event_monitor.cleanup()
def wait(self, name, poll_interval=2, timeout=None, clean=False, show=DiscoSettings()['DISCO_EVENTS']): """ Block until the job *name* has finished. Returns a list URLs to the results files which is typically processed with :func:`result_iterator`. :meth:`Disco.wait` polls the server for the job status every *poll_interval* seconds. It raises a :class:`disco.JobError` if the job hasn't finished in *timeout* seconds, if specified. :param clean: if set to `True`, calls :meth:`Disco.clean` when the job has finished. Note that this only removes records from the master, but not the actual result files. Once you are done with the results, call:: disco.purge(disco.util.jobname(results[0])) to delete the actual result files. :param show: enables console output of job events. You can control this parameter also using the environment variable ``DISCO_EVENTS``, which provides the default. See ``DISCO_EVENTS`` in :mod:`disco.settings`. (*Added in version 0.2.3*) """ event_monitor = EventMonitor(Job(self, name=name), format=show, poll_interval=poll_interval) start_time = time.time() while True: event_monitor.refresh() try: return self.check_results(name, start_time, timeout, poll_interval * 1000) except Continue: continue finally: if clean: self.clean(name) event_monitor.refresh()