def post_runs_id_cancel(run_id: str) -> Response: """ Cancel a running workflow. """ validate_run_id(run_id) cancel_run(run_id) res_body: RunId = {"run_id": run_id} response: Response = jsonify(res_body) response.status_code = POST_STATUS_CODE return response
def get_runs_id_data(run_id: str, subpath: str = "") -> Response: """ This provides a remote url to download a file or directory under the `run_dir` of the sapporo-service. - In the case of `path/to/file`, this returns the file. - In the case of `path/to/dir`, this returns the list of files under directory in JSON format. - In the case of `path/to/dir?download=true`, this returns the directory in zip format. The path is relative to the base directory of each run. See `README.md` in sapporo-service for the structure of `run_dir`. For example, if you want to download the output `foo.txt`, specify something like `outputs/foo.txt`. `..` will be ignored. """ validate_run_id(run_id) if Path(subpath).name[0] == ".": requested_path = \ secure_filepath(str(Path(subpath).parent) ).joinpath(Path(subpath).name) else: requested_path = secure_filepath(subpath) path = get_run_dir(run_id).joinpath(requested_path) if not path.exists(): parent = Path(f"runs/{run_id}/data").joinpath(requested_path.parent) abort(400, f"The specified path: {requested_path} does not exist. " f"Please make another request to `<endpoint>/{parent}/` again " "and check the dir structure.") if path.is_file(): return send_file(path, as_attachment=True) else: if str2bool(request.args.get("download", False)): with NamedTemporaryFile() as f: res = make_archive(f.name, "zip", root_dir=path.parent, base_dir=path.name) if "temp_files" not in g: g.temp_files = [Path(f"{f.name}.zip")] else: g.temp_files.append(Path(f"{f.name}.zip")) return send_file(res, as_attachment=True, attachment_filename=f"{path.name}.zip") else: response: Response = jsonify(path_hierarchy(path, path)) response.status_code = GET_STATUS_CODE return response
def get_runs_id(run_id: str) -> Response: """ This endpoint provides detailed information about a given workflow run. The returned result has information about the outputs produced by this workflow (if available), a log object which allows the stderr and stdout to be retrieved, a log array so stderr/stdout for individual tasks can be retrieved, and the overall state of the workflow run (e.g. RUNNING, see the State section). """ validate_run_id(run_id) res_body: RunLog = get_run_log(run_id) response: Response = jsonify(res_body) response.status_code = GET_STATUS_CODE return response
def get_runs_id_status(run_id: str) -> Response: """ This provides an abbreviated (and likely fast depending on implementation) status of the running workflow, returning a simple result with the overall state of the workflow run (e.g. RUNNING, see the State section). """ validate_run_id(run_id) res_body: RunStatus = { "run_id": run_id, "state": get_state(run_id).name # type: ignore } response: Response = jsonify(res_body) response.status_code = GET_STATUS_CODE return response