def do_rm(args): wids = args.wid for wid in wids: try: ConfigManager.get_from_path_or_submission_lazy( wid, readonly=True).remove_task(wid, keep_output=args.keep) except Exception as e: Logger.critical(f"Can't remove {wid}: " + str(e))
def abort_wids(sids: List[str], wait=True): cm = ConfigManager(db_path=None) for sid in sids: try: row = cm.get_row_for_submission_id_or_path(sid) WorkflowManager.mark_aborted(row.execution_dir, row.submission_id) except Exception as e: Logger.critical(f"Couldn't abort '{sid}': " + str(e)) raise e if wait: Logger.info( "Waiting until completely aborted. This can take up to a few minutes to complete." ) for sid in sids: try: wm = ConfigManager.get_from_path_or_submission_lazy( sid, readonly=True) check_attempts = 0 while not wm.database.get_uncached_status().is_in_final_state( ): time.sleep(1) check_attempts += 1 if check_attempts % 5 == 0: Logger.info( f"Still waiting for '{sid}' to move to final state" ) except Exception as e: Logger.critical( f"Couldn't watch '{sid}' until aborted: {str(e)}") Logger.info(f"Jobs {' '.join(sids)} should be completely aborted now")
def do_watch(args): wid = args.wid refresh = args.refresh if args.once: # --once overrides --refresh refresh = -1 brief = args.brief monochrome = args.monochrome wm = ConfigManager.get_from_path_or_submission_lazy(wid, readonly=False) wm.watch(seconds=refresh, brief=brief, monochrome=monochrome)
def do_resume(args): # if args.job: # from os import getcwd # # # parse and load the job file # Logger.info("Specified job file, ignoring all other parameters") # d = parse_dict(get_file_from_searchname(args.job, getcwd())) # job = PreparedJob(**d) # wm = ConfigManager.get_from_path_or_submission_lazy( # job.execution_dir, readonly=False # ) # # else: wm = ConfigManager.get_from_path_or_submission_lazy(args.wid, readonly=False) run_in_background = False if args.foreground: run_in_background = False elif wm.database.workflowmetadata.configuration.run_in_background: run_in_background = True wm.start_or_submit(run_in_background=run_in_background)
def do_wait(args): wids = args.wid statuses = {} for wid in wids: wm = ConfigManager.get_from_path_or_submission_lazy(wid, readonly=True) Logger.info(f"Waiting for '{wid}' to finish") status = wm.database.get_uncached_status() while not status.is_in_final_state(): sleep(2) status = wm.database.get_uncached_status() statuses[wid] = (wm.submission_id, status) Logger.info( f"Workflow {wid} finished with status: {status.to_string()}") collapsed_status = TaskStatus.collapse_states( [s[1] for s in statuses.values()]) rc = collapsed_status.get_exit_code() Logger.info( f"All workflows finished with collapsed status {collapsed_status.to_string()}, exiting with rc={rc}" ) sys.exit(rc)
def do_pause(args): wm = ConfigManager.get_from_path_or_submission_lazy(args.wid, readonly=True) wm.mark_paused(wm.execution_dir)
def do_rawquery(args): wid = args.wid wm = ConfigManager.get_from_path_or_submission_lazy(wid, readonly=True) with wm.database.with_cursor() as cursor: result = cursor.execute(args.query).fetchall() return print(tabulate.tabulate(result))