diff --git a/schema/versions/44d5bbbf2615_workspaces_init.py b/schema/versions/44d5bbbf2615_workspaces_init.py index c73021e8c7fc9868820760f30be3bd4f7e5f6228..dd3f1e85f83d38c080a21dd364d05e3705496d7a 100644 --- a/schema/versions/44d5bbbf2615_workspaces_init.py +++ b/schema/versions/44d5bbbf2615_workspaces_init.py @@ -45,7 +45,13 @@ def upgrade(): # populate with some initial data op.execute("INSERT INTO workflows (workflow_name) VALUES ('null')") - op.execute("INSERT INTO workflow_templates (workflow_name, filename, content) VALUES ('null', 'null.sh', E'null {{arguments}}')") + op.execute("INSERT INTO workflow_templates (workflow_name, filename, content) " + "VALUES ('null', 'null.condor', E'executable = null.sh\narguments = \"{{arguments}}\"" + "\nerror = null.err\nlog = condor.log\nqueue')") + op.execute("INSERT INTO workflow_templates (workflow_name, filename, content) VALUES " + "('null', 'null.sh', E'#!/bin/sh\n\nnull $*')") + op.execute("INSERT INTO workflow_templates (workflow_name, filename, content) VALUES " + "('null', 'null.dag', 'JOB null null.condor')") def downgrade(): diff --git a/shared/workspaces/setup.py b/shared/workspaces/setup.py index c015bfe242e3fee76789539baa38daa9931f2f95..9747766b3bb10366d8c91226658cd836ee6d949f 100644 --- a/shared/workspaces/setup.py +++ b/shared/workspaces/setup.py @@ -35,6 +35,6 @@ setup( 'Programming Language :: Python :: 3.8' ], entry_points={ - 'console_scripts': [''] + 'console_scripts': ['workflow = workspaces.cli:main'] }, ) diff --git a/shared/workspaces/src/workspaces/cli.py b/shared/workspaces/src/workspaces/cli.py new file mode 100644 index 0000000000000000000000000000000000000000..c2bc855a2c1f0f2ae6434b007e58869df88ace6e --- /dev/null +++ b/shared/workspaces/src/workspaces/cli.py @@ -0,0 +1,73 @@ +""" +This is a workflow CLI. The purpose here is two-fold: + +1. Simplify submitting workflow requests manually +2. Enable debugging of workflows by directly evaluating them +""" + +import argparse as ap +import json +from pathlib import Path + +from workspaces.services import WorkflowService + + +def submit_request(ns: ap.Namespace): + """ + Submit a request to the REST API for execution. + :param namespace: + :return: + """ + # 1. Look up the REST API location in Capo + # 2. Send encode and send this request + # 3. Start listening for workflow events on this request + # 4. Quit when the final message comes back + print(ns) + raise NotImplementedError + + +def debug_workflow(ns: ap.Namespace): + """ + Pretend to be a workflow service and evaluate a request ourselves. + :param namespace: + :return: + """ + service = WorkflowService() + + # handle the argument + arg = None + if ns.inline_argument: + arg = json.loads(ns.inline_argument) + elif ns.argument_file: + arg = json.load(Path(ns.argument_file)) + + # ask the service to execute this request + service.execute(ns.name, arg, ns.file) + + +def main(): + parser = ap.ArgumentParser("workflow") + subparsers = parser.add_subparsers() + + # subcommand 1: submit a workflow request + submit = subparsers.add_parser("submit", help="Submit request to workflow service") + submit.add_argument('name', nargs=1, help='Name of the workflow to request executing') + submit.add_argument('file', nargs='*', help='Files to add to the request') + group = submit.add_mutually_exclusive_group() + group.add_argument('-i', '--inline-argument', nargs=1, type=str, + help='Argument to the workflow, as literal JSON string') + group.add_argument('-f', '--argument-file', nargs=1, type=Path, help='Argument to the workflow, as file containing JSON') + submit.set_defaults(func=submit_request) + + # subcommand 2: debug a workflow request + debug = subparsers.add_parser('debug', help='Evaluate a workflow service request locally (developer command)') + debug.add_argument('name', nargs=1, help='Name of the workflow to request executing') + debug.add_argument('file', nargs='*', help='Files to add to the request') + group = debug.add_mutually_exclusive_group() + group.add_argument('-i', '--inline-argument', nargs=1, type=str, + help='Argument to the workflow, as literal JSON string') + group.add_argument('-f', '--argument-file', nargs=1, type=Path, help='Argument to the workflow, as file containing JSON') + debug.set_defaults(func=debug_workflow) + + args = parser.parse_args() + args.func(args) \ No newline at end of file