def run_from_jobfile( workflow: Union[str, j.Tool, Type[j.Tool]], jobfile: PreparedJob, engine: Union[str, Engine, None] = None, wait: bool = False, # specific engine args cromwell_jar: Optional[str] = None, cromwell_url: Optional[str] = None, ): cm = ConfigManager(db_path=jobfile.db_path) if not workflow: raise Exception("Couldn't find workflow with name: " + str(workflow)) row = cm.create_task_base( wf=workflow, job=jobfile, ) jobfile.execution_dir = row.execution_dir jobfile.output_dir = row.output_dir # set logger for submit Logger.set_write_level(Logger.CONSOLE_LEVEL) logpath = os.path.join( WorkflowManager.get_path_for_component_and_dir( row.execution_dir, WorkflowManager.WorkflowManagerPath.logs), "janis-submit.log", ) Logger.WRITE_LEVELS = {Logger.CONSOLE_LEVEL: (logpath, open(logpath, "a"))} Logger.debug(f"Set submission logging to '{logpath}'") print(row.submission_id, file=sys.stdout) eng = get_engine_from_eng( engine or jobfile.engine, wid=row.submission_id, execdir=WorkflowManager.get_path_for_component_and_dir( row.execution_dir, WorkflowManager.WorkflowManagerPath.execution), confdir=WorkflowManager.get_path_for_component_and_dir( row.execution_dir, WorkflowManager.WorkflowManagerPath.configuration), logfile=os.path.join( WorkflowManager.get_path_for_component_and_dir( row.execution_dir, WorkflowManager.WorkflowManagerPath.logs), "engine.log", ), cromwell_jar=cromwell_jar, cromwell_url=cromwell_url, ) try: wm = WorkflowManager.from_janis( submission_id=row.submission_id, tool=workflow, engine=eng, prepared_submission=jobfile, wait=wait, ) Logger.log("Finished starting task") return wm except KeyboardInterrupt: Logger.info("Exiting...") try: wm.abort() except: pass except Exception as e: # Have to make sure we stop the engine if something happens when creating the task that causes # janis to exit early eng.stop_engine() raise e return wm
def fromjanis( workflow: Union[str, j.Tool, Type[j.Tool]], name: str = None, engine: Union[str, Engine] = None, filescheme: Union[str, FileScheme] = LocalFileScheme(), validation_reqs=None, batchrun_reqs=None, hints: Optional[Dict[str, str]] = None, output_dir: Optional[str] = None, dryrun: bool = False, inputs: Union[str, dict] = None, required_inputs: dict = None, watch=True, max_cores=None, max_memory=None, force=False, keep_intermediate_files=False, recipes=None, run_in_background=True, run_in_foreground=None, dbconfig=None, only_toolbox=False, no_store=False, allow_empty_container=False, check_files=True, container_override: dict = None, **kwargs, ): cm = ConfigManager.manager() jc = JanisConfiguration.manager() wf: Optional[Tool] = resolve_tool( tool=workflow, name=name, from_toolshed=True, only_toolbox=only_toolbox, force=force, ) if not wf: raise Exception("Couldn't find workflow with name: " + str(workflow)) # if isinstance(tool, j.CommandTool): # tool = tool.wrapped_in_wf() # elif isinstance(tool, j.CodeTool): # tool = tool.wrapped_in_wf() # organise inputs inputsdict = {} if recipes: valuesfromrecipe = jc.recipes.get_recipe_for_keys(recipes) inputsdict.update(valuesfromrecipe) inputsdict.update( cascade_inputs( wf=wf, inputs=inputs, required_inputs=required_inputs, batchrun_options=batchrun_reqs, )) row = cm.create_task_base(wf, outdir=output_dir, store_in_centraldb=not no_store) print(row.wid, file=sys.stdout) engine = engine or jc.engine eng = get_engine_from_eng( engine, wid=row.wid, execdir=WorkflowManager.get_path_for_component_and_dir( row.outputdir, WorkflowManager.WorkflowManagerPath.execution), confdir=WorkflowManager.get_path_for_component_and_dir( row.outputdir, WorkflowManager.WorkflowManagerPath.configuration), logfile=os.path.join( WorkflowManager.get_path_for_component_and_dir( row.outputdir, WorkflowManager.WorkflowManagerPath.logs), "engine.log", ), watch=watch, **kwargs, ) fs = get_filescheme_from_fs(filescheme, **kwargs) environment = Environment(f"custom_{wf.id()}", eng, fs) try: # Note: run_in_foreground can be None, so # (not (run_in_foreground is True)) != (run_in_foreground is False) should_run_in_background = (run_in_background is True or jc.run_in_background is True ) and not (run_in_foreground is True) tm = cm.start_task( wid=row.wid, tool=wf, environment=environment, validation_requirements=validation_reqs, batchrun_requirements=batchrun_reqs, task_path=row.outputdir, hints=hints, inputs_dict=inputsdict, dryrun=dryrun, watch=watch, max_cores=max_cores, max_memory=max_memory, keep_intermediate_files=keep_intermediate_files, run_in_background=should_run_in_background, dbconfig=dbconfig, allow_empty_container=allow_empty_container, container_override=container_override, check_files=check_files, ) Logger.log("Finished starting task task") return tm except KeyboardInterrupt: Logger.info("Exiting...") except Exception as e: # Have to make sure we stop the engine if something happens when creating the task that causes # janis to exit early environment.engine.stop_engine() raise e