def get_postproc_results(self) -> Run: """Get results of a post-processing run. The result is None if no entry for a post-porcessing run is found in the workflow handle. Returns ------- flowserv.client.app.run.Run """ with self.service() as api: doc = api.workflows().get_workflow(workflow_id=self.workflow_id) if wflbls.POSTPROC_RUN in doc: return Run(doc=doc[wflbls.POSTPROC_RUN], service=self.service)
def poll_run(self, run_id) -> Run: """Get run result handle for a given run. Raises an unauthorized access error if the user does not have read access to the run. Parameters ---------- run_id: string Unique run identifier Returns ------- flowserv.client.app.run.Run """ with self.service() as api: return Run(doc=api.runs().get_run(run_id=run_id), service=self.service)
def display_runfiles(run: Run): """Display all result files for a given workflow run. Parameters ---------- run: flowserv.app.result.RunResult Run result handle. """ for file in run.files(): ftype = file.format.get('type') f = file.load().open() if file.title: st.subheader(file.title) if ftype == 'csv': show_table(f, spec=file.format) elif ftype == 'image': show_image(f, spec=file.format) elif ftype == 'json': show_json(f, spec=file.format) elif ftype == 'plaintext': show_text(f, spec=file.format)
def start_run(self, arguments: Dict, config: Optional[Dict] = None, poll_interval: Optional[int] = None) -> Run: """Run the associated workflow for the given set of arguments. Parameters ---------- arguments: dict Dictionary of user-provided arguments. config: dict, default=None Optional implementation-specific configuration settings that can be used to overwrite settings that were initialized at object creation. poll_interval: int, default=None Optional poll interval that is used to check the state of a run until it is no longer in active state. Returns ------- flowserv.client.app.run.Run """ arguments = self._parameters.set_defaults(arguments=arguments) with self.service() as api: # Upload any argument values as files that are either of type # StringIO or BytesIO. arglist = list() for key, val in arguments.items(): # Convert arguments to the format that is expected by the run # manager. We pay special attention to file parameters. Input # files may be represented as strings, IO buffers or file # objects. para = self._parameters.get(key) if para is None: raise err.UnknownParameterError(key) if para.is_file(): # Upload a given file prior to running the application. upload_file = None target = None if isinstance(val, str): upload_file = FSFile(val) elif isinstance(val, StringIO): buf = BytesIO(val.read().encode('utf8')) upload_file = IOBuffer(buf) elif isinstance(val, BytesIO): upload_file = IOBuffer(val) elif isinstance(val, IOHandle): upload_file = val else: msg = 'invalid argument {} for {}'.format(key, val) raise err.InvalidArgumentError(msg) fh = api.uploads().upload_file(group_id=self.group_id, file=upload_file, name=key) val = serialize_fh(fh[filelbls.FILE_ID], target=target) arglist.append(serialize_arg(key, val)) # Execute the run and return the serialized run handle. run = api.runs().start_run(group_id=self.group_id, arguments=arglist, config=config) rh = Run(doc=run, service=self.service) # Wait for run to finish if active an poll interval is given. while poll_interval and rh.is_active(): time.sleep(poll_interval) rh = self.poll_run(run_id=rh.run_id) pprun = self.get_postproc_results() if pprun is not None: while poll_interval and pprun.is_active(): time.sleep(poll_interval) pprun = self.get_postproc_results() return rh