Skip to content
Snippets Groups Projects
Commit 96531690 authored by Daniel Lyons's avatar Daniel Lyons
Browse files

Add a sketch of a workflow CLI. Add more template files to the null capability.

parent 0d2ed104
No related branches found
No related tags found
No related merge requests found
......@@ -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():
......
......@@ -35,6 +35,6 @@ setup(
'Programming Language :: Python :: 3.8'
],
entry_points={
'console_scripts': ['']
'console_scripts': ['workflow = workspaces.cli:main']
},
)
"""
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment