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/utils/read.py
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""Read various workflow configurations."""
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Any, Dict, Union
|
|
6
|
+
|
|
7
|
+
from requests import get
|
|
8
|
+
from rich.text import Text
|
|
9
|
+
from yaml import safe_load
|
|
10
|
+
|
|
11
|
+
from workflow import DEFAULT_WORKSPACE_PATH, MODULE_PATH
|
|
12
|
+
from workflow.utils.logger import get_logger
|
|
13
|
+
|
|
14
|
+
logger = get_logger("workflow.utils.read")
|
|
15
|
+
|
|
16
|
+
localspaces = Path(DEFAULT_WORKSPACE_PATH).parent
|
|
17
|
+
localstems = [space.stem for space in localspaces.glob("*.y*ml")]
|
|
18
|
+
modulespaces = Path(MODULE_PATH, "workflow", "workspaces")
|
|
19
|
+
modulestems = [space.stem for space in modulespaces.glob("*.y*ml")]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def workspace(source: Union[str, Path]) -> Dict[str, Any]:
|
|
23
|
+
"""Read a workspace configuration from source.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
source (Union[str, Path]): Source of the workspace.
|
|
27
|
+
Can be a URL, a file path, or a namespace name.
|
|
28
|
+
|
|
29
|
+
Raises:
|
|
30
|
+
ValueError: If not a yaml file, source
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
Dict[str, Any]: Workspace Configuration
|
|
34
|
+
"""
|
|
35
|
+
if isinstance(source, Path):
|
|
36
|
+
if source.exists():
|
|
37
|
+
if source.suffix in [".yaml", ".yml"]:
|
|
38
|
+
logger.debug(f"workspace @ {source.as_posix()}")
|
|
39
|
+
return filename(source.as_posix())
|
|
40
|
+
else:
|
|
41
|
+
msg = f"{source} is not a valid yaml file."
|
|
42
|
+
logger.error(msg)
|
|
43
|
+
raise ValueError(msg)
|
|
44
|
+
|
|
45
|
+
if isinstance(source, str):
|
|
46
|
+
if is_valid_url(source):
|
|
47
|
+
logger.info(f"workspace @ {source}")
|
|
48
|
+
return url(source)
|
|
49
|
+
|
|
50
|
+
logger.error(f"workspace: {source} does not exist.")
|
|
51
|
+
raise ValueError(f"workspace {source} does not exist.")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def url(source: str) -> Any:
|
|
55
|
+
"""Read a source URL.
|
|
56
|
+
|
|
57
|
+
Args:
|
|
58
|
+
source (str): The URL to read.
|
|
59
|
+
|
|
60
|
+
Raises:
|
|
61
|
+
error: If the request fails.
|
|
62
|
+
|
|
63
|
+
Returns:
|
|
64
|
+
Any: The source contents.
|
|
65
|
+
"""
|
|
66
|
+
try:
|
|
67
|
+
response = get(source)
|
|
68
|
+
response.raise_for_status()
|
|
69
|
+
return safe_load(response.text)
|
|
70
|
+
except Exception as error:
|
|
71
|
+
logger.exception(error)
|
|
72
|
+
raise error
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def filename(source: str) -> Any:
|
|
76
|
+
"""Read a source filename.
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
source (str): The filename to read.
|
|
80
|
+
|
|
81
|
+
Raises:
|
|
82
|
+
error: If the file cannot be read.
|
|
83
|
+
|
|
84
|
+
Returns:
|
|
85
|
+
Any: The source contents.
|
|
86
|
+
"""
|
|
87
|
+
try:
|
|
88
|
+
with open(source) as stream:
|
|
89
|
+
return safe_load(stream)
|
|
90
|
+
except Exception as error:
|
|
91
|
+
logger.exception(error)
|
|
92
|
+
raise error
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def get_active_workspace() -> Text:
|
|
96
|
+
"""Returns a Text with info about the active workspace.
|
|
97
|
+
|
|
98
|
+
Returns
|
|
99
|
+
-------
|
|
100
|
+
Text
|
|
101
|
+
Text instance with info.
|
|
102
|
+
"""
|
|
103
|
+
_workspace = "workspace"
|
|
104
|
+
text = Text()
|
|
105
|
+
if _workspace in localstems:
|
|
106
|
+
for possibility in localspaces.glob(f"{_workspace}.y*ml"):
|
|
107
|
+
config = workspace(possibility)
|
|
108
|
+
text.append("Currently using ", style="green")
|
|
109
|
+
text.append(f"{config['workspace']} ", style="blue")
|
|
110
|
+
text.append("workspace.", style="green")
|
|
111
|
+
elif _workspace in modulestems:
|
|
112
|
+
for possibility in modulespaces.glob(f"{_workspace}.y*ml"):
|
|
113
|
+
config = workspace(possibility)
|
|
114
|
+
text.append("Currently using ", style="green")
|
|
115
|
+
text.append(f"{config['workspace']} ", style="blue")
|
|
116
|
+
text.append("workspace.", style="green")
|
|
117
|
+
else:
|
|
118
|
+
text.append("There is not active workspace", style="red")
|
|
119
|
+
return text
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def is_valid_url(url: str) -> bool:
|
|
123
|
+
"""Return True if the URL is valid.
|
|
124
|
+
|
|
125
|
+
Args:
|
|
126
|
+
url (str): The URL to validate.
|
|
127
|
+
|
|
128
|
+
Returns:
|
|
129
|
+
bool: True if the URL is valid.
|
|
130
|
+
"""
|
|
131
|
+
regex = re.compile(
|
|
132
|
+
r"^(https?://)?" # http:// or https:// (optional)
|
|
133
|
+
r"("
|
|
134
|
+
r"localhost|" # localhost
|
|
135
|
+
r"((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}" # ipv4
|
|
136
|
+
r"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" # ipv4
|
|
137
|
+
r"|"
|
|
138
|
+
r"([a-zA-Z0-9]+([-.\w]*[a-zA-Z0-9])*" # domain...
|
|
139
|
+
r"(\.[a-zA-Z0-9]{2,3})+)" # ...with top level domain
|
|
140
|
+
r")"
|
|
141
|
+
r"(?::\d{2,5})?" # optional port
|
|
142
|
+
r"(?:/?|[/?]\S+)?$",
|
|
143
|
+
re.IGNORECASE,
|
|
144
|
+
) # optional trailing path/query
|
|
145
|
+
|
|
146
|
+
return re.match(regex, url) is not None
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"""Functions to render objects to rich.console."""
|
|
2
|
+
|
|
3
|
+
import datetime as dt
|
|
4
|
+
import re
|
|
5
|
+
from json import dumps as json_dumps
|
|
6
|
+
from typing import Any, Dict
|
|
7
|
+
|
|
8
|
+
from rich.text import Text
|
|
9
|
+
|
|
10
|
+
from workflow.http.context import HTTPContext
|
|
11
|
+
from workflow.utils.variables import status_colors, status_symbols
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def render_pipeline(payload: Dict[str, Any]) -> Text:
|
|
15
|
+
"""Renders a pipeline to rich.Text().
|
|
16
|
+
|
|
17
|
+
Parameters
|
|
18
|
+
----------
|
|
19
|
+
payload : Dict[str, Any]
|
|
20
|
+
Pipeline payload.
|
|
21
|
+
|
|
22
|
+
Returns
|
|
23
|
+
-------
|
|
24
|
+
Text
|
|
25
|
+
Rendered text.
|
|
26
|
+
"""
|
|
27
|
+
steps_field = "steps"
|
|
28
|
+
time_fields = ["creation", "start", "stop"]
|
|
29
|
+
text = Text()
|
|
30
|
+
for k, v in payload.items():
|
|
31
|
+
key_value_text = Text()
|
|
32
|
+
if not v:
|
|
33
|
+
continue
|
|
34
|
+
if k in time_fields and v:
|
|
35
|
+
v = dt.datetime.fromtimestamp(v)
|
|
36
|
+
if k == steps_field:
|
|
37
|
+
key_value_text = Text(f"{k}: \n", style="bright_blue")
|
|
38
|
+
for step in v:
|
|
39
|
+
key_value_text.append(f" {step['name']}:")
|
|
40
|
+
key_value_text.append(f"{status_symbols[step['status']]}\n")
|
|
41
|
+
else:
|
|
42
|
+
key_value_text = Text(f"{k}: ", style="bright_blue")
|
|
43
|
+
key_value_text.append(
|
|
44
|
+
f"{v}\n", style="white" if k != "status" else status_colors[v]
|
|
45
|
+
)
|
|
46
|
+
text.append_text(key_value_text)
|
|
47
|
+
return text
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def render_config(http: HTTPContext, payload: Dict[str, Any]) -> Text:
|
|
51
|
+
"""Renders a config to rich.Text().
|
|
52
|
+
|
|
53
|
+
Parameters
|
|
54
|
+
----------
|
|
55
|
+
http : HTTPContext
|
|
56
|
+
Workflow Http context.
|
|
57
|
+
payload : Dict[str, Any]
|
|
58
|
+
Config payload.
|
|
59
|
+
|
|
60
|
+
Returns
|
|
61
|
+
-------
|
|
62
|
+
Text
|
|
63
|
+
Rendered text.
|
|
64
|
+
"""
|
|
65
|
+
text = Text()
|
|
66
|
+
hidden_keys = ["yaml", "services", "name"]
|
|
67
|
+
query = json_dumps({"id": {"$in": payload["pipelines"]}})
|
|
68
|
+
projection = json_dumps({"id": 1, "status": 1})
|
|
69
|
+
pipelines_statuses = http.pipelines.get_pipelines(
|
|
70
|
+
name=payload["name"],
|
|
71
|
+
query=query,
|
|
72
|
+
projection=projection,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
for k, v in payload.items():
|
|
76
|
+
if k in hidden_keys:
|
|
77
|
+
continue
|
|
78
|
+
key_value_text = Text()
|
|
79
|
+
if k == "pipelines":
|
|
80
|
+
key_value_text.append(f"{k}: \n", style="bright_blue")
|
|
81
|
+
for child in pipelines_statuses:
|
|
82
|
+
key_value_text.append(
|
|
83
|
+
f"\t{child['id']}: ", # type: ignore
|
|
84
|
+
style=status_colors[child["status"]], # type: ignore
|
|
85
|
+
)
|
|
86
|
+
key_value_text.append(
|
|
87
|
+
f"{status_symbols[child['status']]}\n", # type: ignore
|
|
88
|
+
style=status_colors[child["status"]], # type: ignore
|
|
89
|
+
)
|
|
90
|
+
text.append_text(key_value_text)
|
|
91
|
+
continue
|
|
92
|
+
key_value_text.append(f"{k}: ", style="bright_blue")
|
|
93
|
+
key_value_text.append(f"{v}\n", style="white")
|
|
94
|
+
text.append_text(key_value_text)
|
|
95
|
+
|
|
96
|
+
return text
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def clean_output(message: str) -> str:
|
|
100
|
+
"""Cleans strings from Click.command output.
|
|
101
|
+
|
|
102
|
+
Parameters
|
|
103
|
+
----------
|
|
104
|
+
message : str
|
|
105
|
+
String to be cleaned.
|
|
106
|
+
|
|
107
|
+
Returns
|
|
108
|
+
-------
|
|
109
|
+
str
|
|
110
|
+
Escaped string.
|
|
111
|
+
"""
|
|
112
|
+
ansi_escape = re.compile(r"\x1B[@-_][0-?]*[ -/]*[@-~]")
|
|
113
|
+
return ansi_escape.sub("", message)
|
workflow/utils/tmate.sh
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
|
|
3
|
+
# Send echo to stderr
|
|
4
|
+
echoerr() { echo "$@" 1>&2; }
|
|
5
|
+
|
|
6
|
+
# Start tmate session
|
|
7
|
+
tmate -S /tmp/tmate.sock new-session -d
|
|
8
|
+
|
|
9
|
+
# Wait for session to be ready
|
|
10
|
+
tmate -S /tmp/tmate.sock wait tmate-ready
|
|
11
|
+
|
|
12
|
+
# Print connection info
|
|
13
|
+
SSH_CMD=$(tmate -S /tmp/tmate.sock display -p '#{tmate_ssh}')
|
|
14
|
+
echo "SSH Command: $SSH_CMD"
|
|
15
|
+
|
|
16
|
+
# Wait for session to end
|
|
17
|
+
tmate -S /tmp/tmate.sock wait tmate-exit
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"""Utilities for validating data."""
|
|
2
|
+
|
|
3
|
+
import platform
|
|
4
|
+
import re
|
|
5
|
+
import subprocess
|
|
6
|
+
from importlib import import_module
|
|
7
|
+
from sys import getsizeof
|
|
8
|
+
from typing import Any, Callable, Dict, List, Tuple
|
|
9
|
+
|
|
10
|
+
from workflow.definitions.work import Work
|
|
11
|
+
from workflow.utils.logger import get_logger
|
|
12
|
+
|
|
13
|
+
logger = get_logger("workflow.utils.validate")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def url(url: str) -> bool:
|
|
17
|
+
"""Return True if the URL is valid.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
url (str): The URL to validate.
|
|
21
|
+
|
|
22
|
+
Returns:
|
|
23
|
+
bool: True if the URL is valid.
|
|
24
|
+
"""
|
|
25
|
+
regex = re.compile(
|
|
26
|
+
r"^(https?://)?" # http:// or https:// (optional)
|
|
27
|
+
r"("
|
|
28
|
+
r"localhost|" # localhost
|
|
29
|
+
r"((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}" # ipv4
|
|
30
|
+
r"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" # ipv4
|
|
31
|
+
r"|"
|
|
32
|
+
r"([a-zA-Z0-9]+([-.\w]*[a-zA-Z0-9])*" # domain...
|
|
33
|
+
r"(\.[a-zA-Z0-9]{2,3})+)" # ...with top level domain
|
|
34
|
+
r")"
|
|
35
|
+
r"(?::\d{2,5})?" # optional port
|
|
36
|
+
r"(?:/?|[/?]\S+)?$",
|
|
37
|
+
re.IGNORECASE,
|
|
38
|
+
) # optional trailing path/query
|
|
39
|
+
|
|
40
|
+
return re.match(regex, url) is not None
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def function(function: str) -> Callable[..., Any]:
|
|
44
|
+
"""Validate the user function.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
function (str): Name of the user function.
|
|
48
|
+
Must be in the form of 'module.submodule.function'.
|
|
49
|
+
|
|
50
|
+
Raises:
|
|
51
|
+
TypeError: Raised if the function is not callable.
|
|
52
|
+
ImportError: Raised if the function cannot be imported.
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
Callable[..., Any]: The user function.
|
|
56
|
+
"""
|
|
57
|
+
try:
|
|
58
|
+
# Name of the module containing the user function
|
|
59
|
+
module_name, func_name = function.rsplit(".", 1)
|
|
60
|
+
module = import_module(module_name)
|
|
61
|
+
function = getattr(module, func_name)
|
|
62
|
+
logger.debug(f"discovered {function} @ {module.__file__}")
|
|
63
|
+
# Check if the function is callable
|
|
64
|
+
if not callable(function):
|
|
65
|
+
raise TypeError(f"{function} is not callable")
|
|
66
|
+
except Exception as error:
|
|
67
|
+
logger.error(error)
|
|
68
|
+
raise ImportError(f"failed to import: {function}")
|
|
69
|
+
return function
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def command(command: str) -> bool:
|
|
73
|
+
"""Validate the command.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
command (str): Name of the command.
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
bool: True if the command exists, False otherwise.
|
|
80
|
+
"""
|
|
81
|
+
try:
|
|
82
|
+
if platform.system() == "Windows":
|
|
83
|
+
response = subprocess.check_output( # nosec
|
|
84
|
+
["where", command], shell=True, universal_newlines=True
|
|
85
|
+
)
|
|
86
|
+
logger.debug(f"discovered {command} @ {response}")
|
|
87
|
+
else:
|
|
88
|
+
response = subprocess.check_output( # nosec
|
|
89
|
+
["which", command], universal_newlines=True
|
|
90
|
+
)
|
|
91
|
+
logger.debug(f"discovered {command} @ {response}")
|
|
92
|
+
return True
|
|
93
|
+
except subprocess.CalledProcessError:
|
|
94
|
+
return False
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def deployments(config: Dict[str, Any]) -> Tuple[List[str], List[str]]:
|
|
98
|
+
"""Validate deployments.
|
|
99
|
+
|
|
100
|
+
Args:
|
|
101
|
+
config (Dict[str, Any]): Config payload.
|
|
102
|
+
|
|
103
|
+
Returns:
|
|
104
|
+
Tuple[List[str], List[str]]: Unused deployments and orphaned steps.
|
|
105
|
+
"""
|
|
106
|
+
unused_deployments = []
|
|
107
|
+
orphaned_steps = []
|
|
108
|
+
deployments = config.get("deployments", [])
|
|
109
|
+
steps = config["pipeline"]["steps"]
|
|
110
|
+
|
|
111
|
+
for deployment in deployments:
|
|
112
|
+
n_used = int()
|
|
113
|
+
top_level = False
|
|
114
|
+
# ? First case: unused deployments
|
|
115
|
+
if config["pipeline"].get("runs_on", None):
|
|
116
|
+
if deployment["name"] in config["pipeline"]["runs_on"]:
|
|
117
|
+
n_used += 1
|
|
118
|
+
top_level = True
|
|
119
|
+
for step in steps:
|
|
120
|
+
has_runs_on = False
|
|
121
|
+
if step.get("runs_on", None):
|
|
122
|
+
used = deployment["name"] in step["runs_on"]
|
|
123
|
+
has_runs_on = True
|
|
124
|
+
if used:
|
|
125
|
+
n_used += 1
|
|
126
|
+
# ? Second case: orphaned steps
|
|
127
|
+
if not used and not has_runs_on:
|
|
128
|
+
orphaned_steps.append(step["name"])
|
|
129
|
+
if not top_level and not has_runs_on:
|
|
130
|
+
orphaned_steps.append(step["name"])
|
|
131
|
+
|
|
132
|
+
if n_used == 0:
|
|
133
|
+
unused_deployments.append(deployment["name"])
|
|
134
|
+
|
|
135
|
+
return (unused_deployments, list(set(orphaned_steps)))
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def outcome(output: Any) -> Tuple[Dict[str, Any], List[str], List[str]]:
|
|
139
|
+
"""Parse the output, returning results, products, and plots.
|
|
140
|
+
|
|
141
|
+
Args:
|
|
142
|
+
output (Any): The output from the work execution.
|
|
143
|
+
|
|
144
|
+
Returns:
|
|
145
|
+
Tuple[Dict[str, Any], List[str], List[str]]:
|
|
146
|
+
Results, products, and plots.
|
|
147
|
+
"""
|
|
148
|
+
results: Dict[str, Any] = {}
|
|
149
|
+
products: List[str] = []
|
|
150
|
+
plots: List[str] = []
|
|
151
|
+
|
|
152
|
+
if isinstance(output, dict):
|
|
153
|
+
results = output
|
|
154
|
+
elif isinstance(output, tuple):
|
|
155
|
+
# Assign values based on type and position in the tuple
|
|
156
|
+
for item in output:
|
|
157
|
+
if isinstance(item, dict) and not results:
|
|
158
|
+
results = item
|
|
159
|
+
elif isinstance(item, list):
|
|
160
|
+
if not products:
|
|
161
|
+
products = item
|
|
162
|
+
elif not plots:
|
|
163
|
+
plots = item
|
|
164
|
+
else:
|
|
165
|
+
logger.error(f"unable to parse output item {item}")
|
|
166
|
+
else:
|
|
167
|
+
logger.info("unable to parse output from work execution")
|
|
168
|
+
|
|
169
|
+
return results, products, plots
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def size(
|
|
173
|
+
work: Work,
|
|
174
|
+
fields: List[str] = ["results", "products", "plots"],
|
|
175
|
+
size: int = 4_000_000,
|
|
176
|
+
) -> Work:
|
|
177
|
+
"""Check if the data is less than the specified.
|
|
178
|
+
|
|
179
|
+
Args:
|
|
180
|
+
work (Work): Work object.
|
|
181
|
+
fields (List[str], optional): Fields.
|
|
182
|
+
Defaults to ["results", "products", "plots"].
|
|
183
|
+
size (int, optional): Size. Defaults to 4_000_000.
|
|
184
|
+
|
|
185
|
+
Returns:
|
|
186
|
+
Work: Work object.
|
|
187
|
+
"""
|
|
188
|
+
for field in fields:
|
|
189
|
+
data = getattr(work, field)
|
|
190
|
+
fsize: int = getsizeof(data)
|
|
191
|
+
if fsize > size:
|
|
192
|
+
logger.error(
|
|
193
|
+
f"{field} size {fsize/1000000:.2f}MB exceeds max: {size/1000000:.2f}MB"
|
|
194
|
+
)
|
|
195
|
+
# Set the field to None
|
|
196
|
+
logger.warning(f"setting {field} to None")
|
|
197
|
+
setattr(work, field, None)
|
|
198
|
+
return work
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""Variables needed for console printing."""
|
|
2
|
+
|
|
3
|
+
status_colors = {
|
|
4
|
+
"created": "lightblue",
|
|
5
|
+
"queued": "yellow",
|
|
6
|
+
"active": "bright_blue",
|
|
7
|
+
"running": "blue",
|
|
8
|
+
"success": "green",
|
|
9
|
+
"paused": "orange",
|
|
10
|
+
"failure": "red",
|
|
11
|
+
"cancelled": "dark_goldenrod",
|
|
12
|
+
"expired": "dark_goldenrod",
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
status_symbols = {
|
|
16
|
+
"created": "\U000026AA", # white
|
|
17
|
+
"queued": "\U0001F4C5", # 📅
|
|
18
|
+
"active": "\U0001F7E2", # green circle
|
|
19
|
+
"running": "\U0001F3C3", # 🏃
|
|
20
|
+
"success": "\U00002705", # Green check
|
|
21
|
+
"paused": "\U0001F7E1", # yellow
|
|
22
|
+
"failure": "\U0000274C", # cross mark
|
|
23
|
+
"cancelled": "\U0001F6AB", # 🚫
|
|
24
|
+
}
|
workflow/utils/write.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Writing utilities for workflow."""
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Any, Dict, Union
|
|
6
|
+
|
|
7
|
+
import yaml
|
|
8
|
+
|
|
9
|
+
from workflow import DEFAULT_WORKSPACE_PATH
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def workspace(
|
|
13
|
+
source: Union[Path, Dict[str, Any]], destination: Path = DEFAULT_WORKSPACE_PATH
|
|
14
|
+
) -> None:
|
|
15
|
+
"""Write a workspace to a destination.
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
source (Union[Path, Dict[str, Any]]): Workspace to write.
|
|
19
|
+
destination (Path): Destination to write the workspace.
|
|
20
|
+
|
|
21
|
+
Raises:
|
|
22
|
+
ValueError: If source is not a dictionary or a file path.
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
None: None
|
|
26
|
+
"""
|
|
27
|
+
if not destination.parent.exists():
|
|
28
|
+
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
29
|
+
# If destination file exists, move it to a backup location file.
|
|
30
|
+
date: str = datetime.now().strftime("%Y%m%d%H%M%S")
|
|
31
|
+
if destination.exists():
|
|
32
|
+
destination.replace(destination.with_suffix(f".{date}.bak"))
|
|
33
|
+
# Make sure the source path exists.
|
|
34
|
+
if isinstance(source, Path):
|
|
35
|
+
assert source.exists(), f"workspace {source} does not exist."
|
|
36
|
+
source.replace(destination)
|
|
37
|
+
return
|
|
38
|
+
# Write dictionary to destination.
|
|
39
|
+
elif isinstance(source, dict): # type: ignore
|
|
40
|
+
with open(destination, "w") as filename:
|
|
41
|
+
yaml.dump(source, filename)
|
|
42
|
+
return
|
|
43
|
+
else:
|
|
44
|
+
raise ValueError(f"source {source} is not a dictionary or a file path.")
|
|
File without changes
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
workspace: chimefrb
|
|
2
|
+
|
|
3
|
+
sites:
|
|
4
|
+
- local
|
|
5
|
+
- chime
|
|
6
|
+
- kko
|
|
7
|
+
- gbo
|
|
8
|
+
- hco
|
|
9
|
+
- aro
|
|
10
|
+
- canfar
|
|
11
|
+
- cedar
|
|
12
|
+
- calcul-quebec
|
|
13
|
+
|
|
14
|
+
http:
|
|
15
|
+
baseurls:
|
|
16
|
+
buckets: "https://frb.chimenet.ca/buckets"
|
|
17
|
+
results: "https://frb.chimenet.ca/results"
|
|
18
|
+
pipelines: "https://frb.chimenet.ca/pipelines"
|
|
19
|
+
loki: "https://frb.chimenet.ca/loki/loki/api/v1/push"
|
|
20
|
+
# This is the prefix url to make a output data plot or product accessible to the user
|
|
21
|
+
products: "https://frb.chimenet.ca/frb-master/v1/events/query-file?filename="
|
|
22
|
+
|
|
23
|
+
archive:
|
|
24
|
+
posix:
|
|
25
|
+
base: "/data/frb-archiver"
|
|
26
|
+
buckets: "/data/frb-archiver/buckets"
|
|
27
|
+
results: "/data/frb-archiver/results"
|
|
28
|
+
pipelines: "/data/frb-archiver/pipelines"
|
|
29
|
+
loki: "/data/frb-archiver/loki"
|
|
30
|
+
products: "/data/frb-archiver/products"
|
|
31
|
+
s3:
|
|
32
|
+
minio:
|
|
33
|
+
url: "https://s3.us-west-2.amazonaws.com/frb-archiver"
|
|
34
|
+
|
|
35
|
+
config:
|
|
36
|
+
archive:
|
|
37
|
+
results: true
|
|
38
|
+
plots:
|
|
39
|
+
methods: ["move", "delete"] # Defines the methods enabled by the workspace admin
|
|
40
|
+
storage: "s3"
|
|
41
|
+
permissions: List[Linux Groups]?
|
|
42
|
+
products:
|
|
43
|
+
methods: ["move", "delete"] # Can also be copy or delete
|
|
44
|
+
storage: "posix"
|
|
45
|
+
logging:
|
|
46
|
+
loki:
|
|
47
|
+
site: "local"
|
|
48
|
+
pipeline: "temp"
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
workspace: development
|
|
2
|
+
|
|
3
|
+
# List the valid sites for this workspace
|
|
4
|
+
sites:
|
|
5
|
+
- local
|
|
6
|
+
|
|
7
|
+
http:
|
|
8
|
+
baseurls:
|
|
9
|
+
configs: http://localhost:8001/v2
|
|
10
|
+
pipelines: http://localhost:8001/v2
|
|
11
|
+
schedules: http://localhost:8001/v2
|
|
12
|
+
buckets: http://localhost:8004
|
|
13
|
+
results: http://localhost:8005
|
|
14
|
+
|
|
15
|
+
archive:
|
|
16
|
+
mounts:
|
|
17
|
+
local: "/"
|
|
18
|
+
|
|
19
|
+
config:
|
|
20
|
+
archive:
|
|
21
|
+
plots:
|
|
22
|
+
methods:
|
|
23
|
+
- "bypass"
|
|
24
|
+
- "copy"
|
|
25
|
+
- "delete"
|
|
26
|
+
- "move"
|
|
27
|
+
storage: "s3"
|
|
28
|
+
products:
|
|
29
|
+
methods:
|
|
30
|
+
- "bypass"
|
|
31
|
+
- "copy"
|
|
32
|
+
- "delete"
|
|
33
|
+
- "move"
|
|
34
|
+
storage: "posix"
|
|
35
|
+
results: true
|
|
36
|
+
permissions:
|
|
37
|
+
posix:
|
|
38
|
+
user: "user"
|
|
39
|
+
group: "chime-frb-ro"
|
|
40
|
+
command: "setfacl -R -m g:{group}:r {path}"
|
|
41
|
+
|
|
42
|
+
deployers:
|
|
43
|
+
local:
|
|
44
|
+
docker:
|
|
45
|
+
# client_url: npipe:////./pipe/docker_engine
|
|
46
|
+
client_url: unix:///var/run/docker.sock
|
|
47
|
+
networks:
|
|
48
|
+
workflow: # This network maps to the docker-compose.yml network name
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
workspace: site-dev
|
|
2
|
+
|
|
3
|
+
# List the valid sites for this workspace
|
|
4
|
+
sites:
|
|
5
|
+
- local
|
|
6
|
+
- chime
|
|
7
|
+
|
|
8
|
+
http:
|
|
9
|
+
baseurls:
|
|
10
|
+
configs:
|
|
11
|
+
- http://localhost:37015/v2
|
|
12
|
+
- http://frb-vsop.chime:37015/v2
|
|
13
|
+
pipelines:
|
|
14
|
+
- http://localhost:37015/v2
|
|
15
|
+
- http://frb-vsop.chime:37015/v2
|
|
16
|
+
schedules:
|
|
17
|
+
- http://localhost:37015/v2
|
|
18
|
+
- http://frb-vsop.chime:37015/v2
|
|
19
|
+
buckets:
|
|
20
|
+
- http://frb-vsop.chime:8004
|
|
21
|
+
- https://frb.chimenet.ca/buckets
|
|
22
|
+
results:
|
|
23
|
+
- http://frb-vsop.chime:8005
|
|
24
|
+
- https://frb.chimenet.ca/results
|
|
25
|
+
|
|
26
|
+
config:
|
|
27
|
+
archive:
|
|
28
|
+
results: true
|
|
29
|
+
|
|
30
|
+
deployers:
|
|
31
|
+
local:
|
|
32
|
+
docker:
|
|
33
|
+
client_url: tcp://frb-vsop.chime:2375
|
|
34
|
+
chime:
|
|
35
|
+
docker:
|
|
36
|
+
client_url: tcp://frb-vsop.chime:2375
|