workflow.core 1.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- workflow/__init__.py +17 -0
- workflow/cli/__init__.py +0 -0
- workflow/cli/buckets.py +124 -0
- workflow/cli/configs.py +279 -0
- workflow/cli/main.py +48 -0
- workflow/cli/pipelines.py +146 -0
- workflow/cli/results.py +168 -0
- workflow/cli/run.py +283 -0
- workflow/cli/schedules.py +234 -0
- workflow/cli/workspace.py +149 -0
- workflow/daemons/__init__.py +0 -0
- workflow/daemons/audit.py +74 -0
- workflow/daemons/transfer.py +255 -0
- workflow/definitions/__init__.py +0 -0
- workflow/definitions/config.py +124 -0
- workflow/definitions/jsonschema.md +28 -0
- workflow/definitions/notify.py +91 -0
- workflow/definitions/work.py +520 -0
- workflow/definitions/workspace.py +252 -0
- workflow/examples/function.py +92 -0
- workflow/examples/sample.svg +12 -0
- workflow/examples/sample.workflow.yml +31 -0
- workflow/helpers/__init__.py +0 -0
- workflow/helpers/date.py +33 -0
- workflow/http/__init__.py +0 -0
- workflow/http/buckets.py +286 -0
- workflow/http/client.py +136 -0
- workflow/http/configs.py +165 -0
- workflow/http/context.py +170 -0
- workflow/http/pipelines.py +123 -0
- workflow/http/results.py +305 -0
- workflow/http/schedules.py +157 -0
- workflow/lifecycle/__init__.py +1 -0
- workflow/lifecycle/archive/__init__.py +102 -0
- workflow/lifecycle/archive/http.py +58 -0
- workflow/lifecycle/archive/posix.py +185 -0
- workflow/lifecycle/archive/s3.py +157 -0
- workflow/lifecycle/attempt.py +112 -0
- workflow/lifecycle/configure.py +152 -0
- workflow/lifecycle/execute.py +159 -0
- workflow/utils/__init__.py +0 -0
- workflow/utils/decorators.py +29 -0
- workflow/utils/logger.py +93 -0
- workflow/utils/prompt.py +26 -0
- workflow/utils/read.py +146 -0
- workflow/utils/renderers.py +113 -0
- workflow/utils/tmate.sh +17 -0
- workflow/utils/validate.py +198 -0
- workflow/utils/variables.py +24 -0
- workflow/utils/write.py +44 -0
- workflow/workspaces/__init__.py +0 -0
- workflow/workspaces/chimefrb.yml +48 -0
- workflow/workspaces/development.yml +48 -0
- workflow/workspaces/site-dev.yml +36 -0
- workflow_core-1.4.0.dist-info/METADATA +115 -0
- workflow_core-1.4.0.dist-info/RECORD +58 -0
- workflow_core-1.4.0.dist-info/WHEEL +4 -0
- workflow_core-1.4.0.dist-info/entry_points.txt +3 -0
workflow/__init__.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Top-level imports for Tasks API."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from warnings import filterwarnings
|
|
5
|
+
|
|
6
|
+
# Ignore UserWarnings from pydantic_settings module
|
|
7
|
+
# These usually come when no docker secrets are found
|
|
8
|
+
filterwarnings("ignore", category=UserWarning, module="pydantic_settings")
|
|
9
|
+
|
|
10
|
+
# Root path to the Workflow Module
|
|
11
|
+
MODULE_PATH: Path = Path(__file__).absolute().parent.parent
|
|
12
|
+
# Path to local configurations
|
|
13
|
+
CONFIG_PATH: Path = Path.home() / ".config" / "workflow"
|
|
14
|
+
# Active Workspace Path
|
|
15
|
+
DEFAULT_WORKSPACE_PATH: Path = CONFIG_PATH / "workspace.yml"
|
|
16
|
+
# Workflow Client Version
|
|
17
|
+
__version__ = "1.4.0" # {x-release-please-version}
|
workflow/cli/__init__.py
ADDED
|
File without changes
|
workflow/cli/buckets.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"""Common Workflow Utilities."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
4
|
+
|
|
5
|
+
import click
|
|
6
|
+
from rich import pretty
|
|
7
|
+
from rich.console import Console
|
|
8
|
+
from rich.table import Table
|
|
9
|
+
|
|
10
|
+
from workflow.http.context import HTTPContext
|
|
11
|
+
|
|
12
|
+
pretty.install()
|
|
13
|
+
console = Console()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
table = Table(
|
|
17
|
+
title="\nWorkflow",
|
|
18
|
+
show_header=True,
|
|
19
|
+
header_style="magenta",
|
|
20
|
+
title_style="bold magenta",
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@click.group(name="buckets", help="Manage Workflow Buckets.")
|
|
25
|
+
def buckets():
|
|
26
|
+
"""Manage Workflow Buckets."""
|
|
27
|
+
pass
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@buckets.command("rm", help="Remove work from a bucket.")
|
|
31
|
+
@click.argument("bucket", type=str, required=True)
|
|
32
|
+
@click.option("-s", "--status", type=str, required=False, help="Filter by status.")
|
|
33
|
+
@click.option(
|
|
34
|
+
"-e", "--event", type=int, required=False, multiple=True, help="Filter by event."
|
|
35
|
+
)
|
|
36
|
+
@click.option(
|
|
37
|
+
"-t", "--tag", type=str, required=False, multiple=True, help="Filter by tag."
|
|
38
|
+
)
|
|
39
|
+
@click.option("-p", "--parent", type=str, required=False, help="Filter by parent.")
|
|
40
|
+
@click.option("-f", "--force", is_flag=True, help="Do not prompt for confirmation")
|
|
41
|
+
def remove(
|
|
42
|
+
bucket: str,
|
|
43
|
+
status: Optional[str] = None,
|
|
44
|
+
event: Optional[Tuple[int]] = None,
|
|
45
|
+
tag: Optional[Tuple[str]] = None,
|
|
46
|
+
parent: Optional[str] = None,
|
|
47
|
+
force: bool = False,
|
|
48
|
+
):
|
|
49
|
+
"""Remove work[s] from the buckets.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
bucket (str): Name of the bucket.
|
|
53
|
+
status (Optional[str], optional): Status of work. Defaults to None.
|
|
54
|
+
event (Optional[Tuple[int]], optional): Filter by event. Defaults to None.
|
|
55
|
+
tag (Optional[Tuple[str]], optional): Filter by tag. Defaults to None.
|
|
56
|
+
parent (Optional[str], optional): Filter by parent. Defaults to None.
|
|
57
|
+
force (bool, optional): Do not prompt for confirmation. Defaults to False.
|
|
58
|
+
"""
|
|
59
|
+
http = HTTPContext()
|
|
60
|
+
events: Optional[List[int]] = None
|
|
61
|
+
tags: Optional[List[str]] = None
|
|
62
|
+
if event:
|
|
63
|
+
events = list(event)
|
|
64
|
+
if tag:
|
|
65
|
+
tags = list(tag)
|
|
66
|
+
http.buckets.delete_many(
|
|
67
|
+
pipeline=bucket,
|
|
68
|
+
status=status,
|
|
69
|
+
events=events,
|
|
70
|
+
tags=tags,
|
|
71
|
+
parent=parent,
|
|
72
|
+
force=force,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@buckets.command("ls")
|
|
77
|
+
@click.option("-d", "--details", is_flag=True, help="List details.")
|
|
78
|
+
def ls(details: bool = False):
|
|
79
|
+
"""List Buckets."""
|
|
80
|
+
http = HTTPContext()
|
|
81
|
+
if details:
|
|
82
|
+
for key in ["name", "total", "queued", "running", "success", "failure"]:
|
|
83
|
+
table.add_column(key, justify="right")
|
|
84
|
+
pipelines = http.buckets.pipelines()
|
|
85
|
+
for pipeline in pipelines:
|
|
86
|
+
info = http.buckets.status(pipeline=pipeline)
|
|
87
|
+
row = create_row(info)
|
|
88
|
+
table.add_row(pipeline, *row)
|
|
89
|
+
else:
|
|
90
|
+
pipelines = http.buckets.pipelines()
|
|
91
|
+
table.add_column("Buckets", max_width=50, justify="left")
|
|
92
|
+
for pipeline in pipelines:
|
|
93
|
+
table.add_row(pipeline)
|
|
94
|
+
console.print(table)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
@buckets.command("ps", help="List work in a bucket.")
|
|
98
|
+
@click.argument("bucket", type=str, required=True, default=None)
|
|
99
|
+
@click.option("-c", "--count", type=int, default=1, help="Number of works to list.")
|
|
100
|
+
def ps(bucket: str, count: int):
|
|
101
|
+
"""List work in the bucket.
|
|
102
|
+
|
|
103
|
+
Args:
|
|
104
|
+
bucket (str): Name of the bucket.
|
|
105
|
+
count (int): Number of works to list.
|
|
106
|
+
"""
|
|
107
|
+
http = HTTPContext()
|
|
108
|
+
work = http.buckets.view(query={"pipeline": bucket}, projection={}, limit=count)
|
|
109
|
+
console.print(work)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def create_row(details: Dict[str, Any]) -> List[str]:
|
|
113
|
+
"""Create a row of data for the table.
|
|
114
|
+
|
|
115
|
+
Args:
|
|
116
|
+
details (Dict[str, Any]): Details of the bucket.
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
List[str]: List of values.
|
|
120
|
+
"""
|
|
121
|
+
row_data: List[str] = []
|
|
122
|
+
for value in details.values():
|
|
123
|
+
row_data.append(str(value))
|
|
124
|
+
return row_data
|
workflow/cli/configs.py
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"""Manage workflow pipelines."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from typing import Any, Dict, List, Optional
|
|
5
|
+
|
|
6
|
+
import click
|
|
7
|
+
import requests
|
|
8
|
+
import yaml
|
|
9
|
+
from rich import pretty
|
|
10
|
+
from rich.console import Console
|
|
11
|
+
from rich.json import JSON
|
|
12
|
+
from rich.table import Table
|
|
13
|
+
from rich.text import Text
|
|
14
|
+
from yaml import safe_load
|
|
15
|
+
from yaml.loader import SafeLoader
|
|
16
|
+
|
|
17
|
+
from workflow.http.context import HTTPContext
|
|
18
|
+
from workflow.utils import validate
|
|
19
|
+
from workflow.utils.renderers import render_config
|
|
20
|
+
|
|
21
|
+
pretty.install()
|
|
22
|
+
console = Console()
|
|
23
|
+
|
|
24
|
+
table = Table(
|
|
25
|
+
title="\nWorkflow Configs",
|
|
26
|
+
show_header=True,
|
|
27
|
+
header_style="magenta",
|
|
28
|
+
title_style="bold magenta",
|
|
29
|
+
min_width=50,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
BASE_URL = "https://frb.chimenet.ca/pipelines"
|
|
33
|
+
STATUS = ["created", "queued", "running", "success", "failure", "cancelled"]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@click.group(name="configs", help="Manage Workflow Configs. Version 2.")
|
|
37
|
+
def configs():
|
|
38
|
+
"""Manage Workflow Configs."""
|
|
39
|
+
pass
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@configs.command("version", help="Backend version.")
|
|
43
|
+
def version():
|
|
44
|
+
"""Get version of the pipelines service."""
|
|
45
|
+
http = HTTPContext()
|
|
46
|
+
console.print(http.configs.info())
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@configs.command("count", help="Count objects per collection.")
|
|
50
|
+
def count():
|
|
51
|
+
"""Count objects in a database."""
|
|
52
|
+
http = HTTPContext()
|
|
53
|
+
counts = http.configs.count()
|
|
54
|
+
table.add_column("Name", max_width=50, justify="left", style="blue")
|
|
55
|
+
table.add_column("Count", max_width=50, justify="left")
|
|
56
|
+
total = int()
|
|
57
|
+
for k, v in counts.items():
|
|
58
|
+
table.add_row(k, str(v))
|
|
59
|
+
total += v
|
|
60
|
+
table.add_section()
|
|
61
|
+
table.add_row("Total", str(total))
|
|
62
|
+
console.print(table)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@configs.command("deploy", help="Deploy a workflow config.")
|
|
66
|
+
@click.argument(
|
|
67
|
+
"filename",
|
|
68
|
+
type=click.Path(exists=True, dir_okay=False, readable=True),
|
|
69
|
+
required=True,
|
|
70
|
+
)
|
|
71
|
+
def deploy(filename: click.Path):
|
|
72
|
+
"""Deploy a workflow config.
|
|
73
|
+
|
|
74
|
+
Parameters
|
|
75
|
+
----------
|
|
76
|
+
filename : click.Path
|
|
77
|
+
File path.
|
|
78
|
+
"""
|
|
79
|
+
http = HTTPContext()
|
|
80
|
+
filepath: str = str(filename)
|
|
81
|
+
data: Dict[str, Any] = {}
|
|
82
|
+
with open(filepath) as reader:
|
|
83
|
+
data = yaml.load(reader, Loader=SafeLoader) # type: ignore
|
|
84
|
+
|
|
85
|
+
# ? Check unused deployments and orphaned steps
|
|
86
|
+
unused_deployments: List[str] = list()
|
|
87
|
+
orphaned_steps: List[str] = list()
|
|
88
|
+
if data.get("deployments", None):
|
|
89
|
+
unused_deployments, orphaned_steps = validate.deployments(config=data)
|
|
90
|
+
if any(unused_deployments):
|
|
91
|
+
answer = console.input(
|
|
92
|
+
f"The following deployments are not being used: {unused_deployments},"
|
|
93
|
+
" do you wish to continue? (Y/n):"
|
|
94
|
+
)
|
|
95
|
+
if answer.lower() != "y":
|
|
96
|
+
console.print("Cancelling", style="red")
|
|
97
|
+
return
|
|
98
|
+
if any(orphaned_steps):
|
|
99
|
+
answer = console.input(
|
|
100
|
+
f"The following steps {orphaned_steps} does not have a runs_on "
|
|
101
|
+
"even though you have defined deployments, "
|
|
102
|
+
"do you wish to continue? (Y/n):",
|
|
103
|
+
)
|
|
104
|
+
if answer.lower() != "y":
|
|
105
|
+
console.print("Cancelling", style="red")
|
|
106
|
+
return
|
|
107
|
+
|
|
108
|
+
try:
|
|
109
|
+
deploy_result = http.configs.deploy(data)
|
|
110
|
+
except requests.HTTPError as deploy_error:
|
|
111
|
+
console.print(deploy_error.response.json()["error_description"][0]["msg"])
|
|
112
|
+
return
|
|
113
|
+
table.add_column(
|
|
114
|
+
"Deploy Result",
|
|
115
|
+
min_width=35,
|
|
116
|
+
max_width=50,
|
|
117
|
+
justify="left",
|
|
118
|
+
style="bright_green",
|
|
119
|
+
)
|
|
120
|
+
if isinstance(deploy_result, dict):
|
|
121
|
+
for k, v in deploy_result.items():
|
|
122
|
+
if k == "config":
|
|
123
|
+
row_text = Text(f"{k}: ", style="magenta")
|
|
124
|
+
row_text.append(f"{v}", style="white")
|
|
125
|
+
table.add_row(row_text)
|
|
126
|
+
if k == "pipelines":
|
|
127
|
+
row_text = Text(f"{k}:\n", style="bright_blue")
|
|
128
|
+
for id in deploy_result[k]:
|
|
129
|
+
row_text.append(f"\t{id}\n", style="white")
|
|
130
|
+
table.add_row(row_text)
|
|
131
|
+
console.print(table)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
@configs.command("ls", help="List Configs.")
|
|
135
|
+
@click.argument("name", type=str, required=False)
|
|
136
|
+
@click.option(
|
|
137
|
+
"quiet",
|
|
138
|
+
"--quiet",
|
|
139
|
+
"-q",
|
|
140
|
+
is_flag=True,
|
|
141
|
+
default=False,
|
|
142
|
+
help="Only show IDs.",
|
|
143
|
+
)
|
|
144
|
+
def ls(name: Optional[str] = None, quiet: bool = False):
|
|
145
|
+
"""List all objects."""
|
|
146
|
+
configs_colums = ["name", "version", "pipelines", "user"]
|
|
147
|
+
projection = {"yaml": 0, "deployments": 0}
|
|
148
|
+
if quiet:
|
|
149
|
+
projection = {"id": 1}
|
|
150
|
+
http = HTTPContext()
|
|
151
|
+
objects = http.configs.get_configs(name=name, projection=json.dumps(projection))
|
|
152
|
+
|
|
153
|
+
# ? Add columns for each key
|
|
154
|
+
table.add_column("ID", max_width=40, justify="left", style="blue")
|
|
155
|
+
if not quiet:
|
|
156
|
+
for key in configs_colums:
|
|
157
|
+
table.add_column(
|
|
158
|
+
key.capitalize().replace("_", " "),
|
|
159
|
+
max_width=50,
|
|
160
|
+
justify="left",
|
|
161
|
+
style="bright_green" if key == "name" else "white",
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
for obj in objects:
|
|
165
|
+
if not quiet:
|
|
166
|
+
table.add_row(
|
|
167
|
+
obj["id"],
|
|
168
|
+
obj["name"],
|
|
169
|
+
obj["version"],
|
|
170
|
+
str(len(obj["pipelines"])),
|
|
171
|
+
obj["user"],
|
|
172
|
+
)
|
|
173
|
+
continue
|
|
174
|
+
table.add_row(obj["id"])
|
|
175
|
+
console.print(table)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
@configs.command("ps", help="Get Configs details.")
|
|
179
|
+
@click.argument("name", type=str, required=True)
|
|
180
|
+
@click.argument("id", type=str, required=True)
|
|
181
|
+
@click.option(
|
|
182
|
+
"--details",
|
|
183
|
+
is_flag=True,
|
|
184
|
+
default=False,
|
|
185
|
+
show_default=True,
|
|
186
|
+
help="Show more details for the object.",
|
|
187
|
+
)
|
|
188
|
+
def ps(name: str, id: str, details: bool):
|
|
189
|
+
"""Show details for an object."""
|
|
190
|
+
http = HTTPContext()
|
|
191
|
+
query: str = json.dumps({"id": id})
|
|
192
|
+
projection: str = json.dumps({})
|
|
193
|
+
console_content = None
|
|
194
|
+
column_max_width = 300
|
|
195
|
+
column_min_width = 40
|
|
196
|
+
try:
|
|
197
|
+
payload = http.configs.get_configs(
|
|
198
|
+
name=name, query=query, projection=projection
|
|
199
|
+
)[0]
|
|
200
|
+
except IndexError:
|
|
201
|
+
error_text = Text("No Configs were found", style="red")
|
|
202
|
+
console_content = error_text
|
|
203
|
+
else:
|
|
204
|
+
text = Text("")
|
|
205
|
+
table.add_column(
|
|
206
|
+
f"Config: {name}",
|
|
207
|
+
min_width=column_min_width,
|
|
208
|
+
max_width=column_max_width,
|
|
209
|
+
justify="left",
|
|
210
|
+
)
|
|
211
|
+
text.append(render_config(http, payload))
|
|
212
|
+
if details:
|
|
213
|
+
table.add_column("Details", max_width=column_max_width, justify="left")
|
|
214
|
+
_details = safe_load(payload["yaml"])
|
|
215
|
+
_details = {
|
|
216
|
+
k: v
|
|
217
|
+
for k, v in _details.items()
|
|
218
|
+
if k not in ["name", "version", "deployments"]
|
|
219
|
+
}
|
|
220
|
+
table.add_row(text, JSON(json.dumps(_details), indent=2))
|
|
221
|
+
else:
|
|
222
|
+
table.add_row(text)
|
|
223
|
+
table.add_section()
|
|
224
|
+
table.add_row(
|
|
225
|
+
Text("Explore pipelines in detail: \n", style="magenta i").append(
|
|
226
|
+
"workflow pipelines ps <config_name> <pipeline_id>",
|
|
227
|
+
style="dark_blue on cyan",
|
|
228
|
+
)
|
|
229
|
+
)
|
|
230
|
+
console_content = table
|
|
231
|
+
finally:
|
|
232
|
+
console.print(console_content)
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
@configs.command("stop", help="Stop managers for a Config.")
|
|
236
|
+
@click.argument("config", type=str, required=True)
|
|
237
|
+
@click.argument("id", type=str, required=True)
|
|
238
|
+
def stop(config: str, id: str):
|
|
239
|
+
"""Stop managers for a Config."""
|
|
240
|
+
http = HTTPContext()
|
|
241
|
+
stop_result = http.configs.stop(config, id)
|
|
242
|
+
if not any(stop_result):
|
|
243
|
+
text = Text("No configurations were stopped.", style="red")
|
|
244
|
+
console.print(text)
|
|
245
|
+
return
|
|
246
|
+
table.add_column("Stopped IDs", max_width=50, justify="left")
|
|
247
|
+
text = Text()
|
|
248
|
+
for k in stop_result.keys():
|
|
249
|
+
if k == "stopped_config":
|
|
250
|
+
text.append("Config: ", style="bright_blue")
|
|
251
|
+
text.append(f"{stop_result[k]}\n")
|
|
252
|
+
if k == "stopped_pipelines":
|
|
253
|
+
text.append("Pipelines: \n", style="bright_blue")
|
|
254
|
+
for id in stop_result["stopped_pipelines"]:
|
|
255
|
+
text.append(f"\t{id}\n")
|
|
256
|
+
table.add_row(text)
|
|
257
|
+
console.print(table)
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
@configs.command("rm", help="Remove a config.")
|
|
261
|
+
@click.argument("config", type=str, required=True)
|
|
262
|
+
@click.argument("id", type=str, required=True)
|
|
263
|
+
def rm(config: str, id: str):
|
|
264
|
+
"""Remove a config."""
|
|
265
|
+
http = HTTPContext()
|
|
266
|
+
content = None
|
|
267
|
+
try:
|
|
268
|
+
delete_result = http.configs.remove(config, id)
|
|
269
|
+
if delete_result.status_code == 204:
|
|
270
|
+
text = Text("No pipeline configurations were deleted.", style="red")
|
|
271
|
+
content = text
|
|
272
|
+
except Exception as e:
|
|
273
|
+
text = Text(f"No configurations were deleted.\nError: {e}", style="red")
|
|
274
|
+
content = text
|
|
275
|
+
else:
|
|
276
|
+
table.add_column("Deleted IDs", max_width=50, justify="left", style="red")
|
|
277
|
+
table.add_row(id)
|
|
278
|
+
content = table
|
|
279
|
+
console.print(content)
|
workflow/cli/main.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""Workflow command line interface."""
|
|
2
|
+
|
|
3
|
+
from typing import List
|
|
4
|
+
|
|
5
|
+
import click
|
|
6
|
+
from rich.console import Console
|
|
7
|
+
|
|
8
|
+
from workflow.cli.buckets import buckets
|
|
9
|
+
from workflow.cli.configs import configs
|
|
10
|
+
from workflow.cli.pipelines import pipelines
|
|
11
|
+
from workflow.cli.results import results
|
|
12
|
+
from workflow.cli.run import run
|
|
13
|
+
from workflow.cli.schedules import schedules
|
|
14
|
+
from workflow.cli.workspace import workspace
|
|
15
|
+
from workflow.daemons.audit import audit
|
|
16
|
+
from workflow.utils.read import get_active_workspace
|
|
17
|
+
|
|
18
|
+
console = Console()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class OrderedCommands(click.Group):
|
|
22
|
+
"""Order Click Commands."""
|
|
23
|
+
|
|
24
|
+
def list_commands(self, ctx: click.Context) -> List[str]:
|
|
25
|
+
"""List Commands."""
|
|
26
|
+
return list(self.commands)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@click.group(cls=OrderedCommands)
|
|
30
|
+
def cli():
|
|
31
|
+
"""Workflow Command Line Interface."""
|
|
32
|
+
# ? Get Workspace
|
|
33
|
+
message = get_active_workspace()
|
|
34
|
+
console.print(message)
|
|
35
|
+
pass
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
cli.add_command(run)
|
|
39
|
+
cli.add_command(buckets)
|
|
40
|
+
cli.add_command(results)
|
|
41
|
+
cli.add_command(configs)
|
|
42
|
+
cli.add_command(pipelines)
|
|
43
|
+
cli.add_command(schedules)
|
|
44
|
+
cli.add_command(workspace)
|
|
45
|
+
cli.add_command(audit)
|
|
46
|
+
|
|
47
|
+
if __name__ == "__main__":
|
|
48
|
+
cli()
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""Manage workflow pipelines."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from typing import Any, Dict, Optional
|
|
5
|
+
|
|
6
|
+
import click
|
|
7
|
+
import requests
|
|
8
|
+
from rich import pretty
|
|
9
|
+
from rich.console import Console
|
|
10
|
+
from rich.table import Table
|
|
11
|
+
from rich.text import Text
|
|
12
|
+
|
|
13
|
+
from workflow.http.context import HTTPContext
|
|
14
|
+
from workflow.utils.renderers import render_pipeline
|
|
15
|
+
from workflow.utils.variables import status_colors
|
|
16
|
+
|
|
17
|
+
pretty.install()
|
|
18
|
+
console = Console()
|
|
19
|
+
|
|
20
|
+
table = Table(
|
|
21
|
+
title="\nWorkflow Pipelines",
|
|
22
|
+
show_header=True,
|
|
23
|
+
header_style="magenta",
|
|
24
|
+
title_style="bold magenta",
|
|
25
|
+
min_width=50,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
BASE_URL = "https://frb.chimenet.ca/pipelines"
|
|
29
|
+
STATUS = ["created", "queued", "running", "success", "failure", "cancelled"]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@click.group(name="pipelines", help="Manage Workflow Pipelines.")
|
|
33
|
+
def pipelines():
|
|
34
|
+
"""Manage Workflow Pipelines."""
|
|
35
|
+
pass
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@pipelines.command("version", help="Backend version.")
|
|
39
|
+
def version():
|
|
40
|
+
"""Get version of the pipelines service."""
|
|
41
|
+
http = HTTPContext()
|
|
42
|
+
console.print(http.pipelines.info())
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@pipelines.command("ls", help="List pipelines.")
|
|
46
|
+
@click.argument("name", type=str, required=False)
|
|
47
|
+
@click.option(
|
|
48
|
+
"quiet",
|
|
49
|
+
"--quiet",
|
|
50
|
+
"-q",
|
|
51
|
+
is_flag=True,
|
|
52
|
+
required=False,
|
|
53
|
+
help="Only show IDs.",
|
|
54
|
+
)
|
|
55
|
+
def ls(name: Optional[str] = None, quiet: Optional[bool] = False):
|
|
56
|
+
"""List all pipelines."""
|
|
57
|
+
pipelines_columns = ["status", "current_stage", "steps"]
|
|
58
|
+
http = HTTPContext()
|
|
59
|
+
objects = http.pipelines.list_pipelines(name)
|
|
60
|
+
table.add_column("ID", max_width=100, justify="left", style="blue")
|
|
61
|
+
for key in pipelines_columns:
|
|
62
|
+
table.add_column(
|
|
63
|
+
key.capitalize().replace("_", " "),
|
|
64
|
+
max_width=50,
|
|
65
|
+
justify="left",
|
|
66
|
+
)
|
|
67
|
+
for obj in objects:
|
|
68
|
+
if not quiet:
|
|
69
|
+
status = Text(obj["status"], style=status_colors[obj["status"]])
|
|
70
|
+
table.add_row(
|
|
71
|
+
obj["id"], status, str(obj["current_stage"]), str(len(obj["steps"]))
|
|
72
|
+
)
|
|
73
|
+
continue
|
|
74
|
+
table.add_row(obj["id"])
|
|
75
|
+
console.print(table)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@pipelines.command("count", help="Count pipeline configurations per collection.")
|
|
79
|
+
def count():
|
|
80
|
+
"""Count pipeline configurations."""
|
|
81
|
+
http = HTTPContext()
|
|
82
|
+
counts = http.pipelines.count()
|
|
83
|
+
table.add_column("Name", max_width=50, justify="left", style="blue")
|
|
84
|
+
table.add_column("Count", max_width=50, justify="left")
|
|
85
|
+
total = int()
|
|
86
|
+
for k, v in counts.items():
|
|
87
|
+
table.add_row(k, str(v))
|
|
88
|
+
total += v
|
|
89
|
+
table.add_section()
|
|
90
|
+
table.add_row("Total", str(total))
|
|
91
|
+
console.print(table)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
@pipelines.command("ps", help="Get pipeline details.")
|
|
95
|
+
@click.argument("pipeline", type=str, required=True)
|
|
96
|
+
@click.argument("id", type=str, required=True)
|
|
97
|
+
def ps(pipeline: str, id: str):
|
|
98
|
+
"""List a pipeline configuration in detail."""
|
|
99
|
+
http = HTTPContext()
|
|
100
|
+
query: str = json.dumps({"id": id})
|
|
101
|
+
projection: str = json.dumps({})
|
|
102
|
+
console_content = None
|
|
103
|
+
column_max_width = 300
|
|
104
|
+
column_min_width = 40
|
|
105
|
+
try:
|
|
106
|
+
payload = http.pipelines.get_pipelines(
|
|
107
|
+
name=pipeline, query=query, projection=projection
|
|
108
|
+
)[
|
|
109
|
+
0 # type: ignore
|
|
110
|
+
]
|
|
111
|
+
except IndexError:
|
|
112
|
+
error_text = Text("No Pipelines were found", style="red")
|
|
113
|
+
console_content = error_text
|
|
114
|
+
else:
|
|
115
|
+
text = Text()
|
|
116
|
+
table.add_column(
|
|
117
|
+
f"Pipeline: {pipeline}",
|
|
118
|
+
min_width=column_min_width,
|
|
119
|
+
max_width=column_max_width,
|
|
120
|
+
justify="left",
|
|
121
|
+
)
|
|
122
|
+
text.append(render_pipeline(payload))
|
|
123
|
+
table.add_row(text)
|
|
124
|
+
console_content = table
|
|
125
|
+
finally:
|
|
126
|
+
console.print(console_content)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def status(
|
|
130
|
+
pipeline: Optional[str] = None,
|
|
131
|
+
query: Optional[Dict[str, Any]] = None,
|
|
132
|
+
projection: Optional[Dict[str, bool]] = None,
|
|
133
|
+
version: str = "v1",
|
|
134
|
+
):
|
|
135
|
+
"""Get status of all pipelines."""
|
|
136
|
+
projected: str = ""
|
|
137
|
+
filter: str = ""
|
|
138
|
+
if projection:
|
|
139
|
+
projected = str(json.dumps(projection))
|
|
140
|
+
if query:
|
|
141
|
+
filter = str(json.dumps(query))
|
|
142
|
+
response = requests.get(
|
|
143
|
+
f"{BASE_URL}/{version}/pipelines",
|
|
144
|
+
params={"name": pipeline, "projection": projected, "query": filter},
|
|
145
|
+
)
|
|
146
|
+
return response.json()
|