workflow.core 1.4.0__tar.gz
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_core-1.4.0/PKG-INFO +115 -0
- workflow_core-1.4.0/README.md +83 -0
- workflow_core-1.4.0/pyproject.toml +56 -0
- workflow_core-1.4.0/workflow/__init__.py +17 -0
- workflow_core-1.4.0/workflow/cli/__init__.py +0 -0
- workflow_core-1.4.0/workflow/cli/buckets.py +124 -0
- workflow_core-1.4.0/workflow/cli/configs.py +279 -0
- workflow_core-1.4.0/workflow/cli/main.py +48 -0
- workflow_core-1.4.0/workflow/cli/pipelines.py +146 -0
- workflow_core-1.4.0/workflow/cli/results.py +168 -0
- workflow_core-1.4.0/workflow/cli/run.py +283 -0
- workflow_core-1.4.0/workflow/cli/schedules.py +234 -0
- workflow_core-1.4.0/workflow/cli/workspace.py +149 -0
- workflow_core-1.4.0/workflow/daemons/__init__.py +0 -0
- workflow_core-1.4.0/workflow/daemons/audit.py +74 -0
- workflow_core-1.4.0/workflow/daemons/transfer.py +255 -0
- workflow_core-1.4.0/workflow/definitions/__init__.py +0 -0
- workflow_core-1.4.0/workflow/definitions/config.py +124 -0
- workflow_core-1.4.0/workflow/definitions/jsonschema.md +28 -0
- workflow_core-1.4.0/workflow/definitions/notify.py +91 -0
- workflow_core-1.4.0/workflow/definitions/work.py +520 -0
- workflow_core-1.4.0/workflow/definitions/workspace.py +252 -0
- workflow_core-1.4.0/workflow/examples/function.py +92 -0
- workflow_core-1.4.0/workflow/examples/sample.svg +12 -0
- workflow_core-1.4.0/workflow/examples/sample.workflow.yml +31 -0
- workflow_core-1.4.0/workflow/helpers/__init__.py +0 -0
- workflow_core-1.4.0/workflow/helpers/date.py +33 -0
- workflow_core-1.4.0/workflow/http/__init__.py +0 -0
- workflow_core-1.4.0/workflow/http/buckets.py +286 -0
- workflow_core-1.4.0/workflow/http/client.py +136 -0
- workflow_core-1.4.0/workflow/http/configs.py +165 -0
- workflow_core-1.4.0/workflow/http/context.py +170 -0
- workflow_core-1.4.0/workflow/http/pipelines.py +123 -0
- workflow_core-1.4.0/workflow/http/results.py +305 -0
- workflow_core-1.4.0/workflow/http/schedules.py +157 -0
- workflow_core-1.4.0/workflow/lifecycle/__init__.py +1 -0
- workflow_core-1.4.0/workflow/lifecycle/archive/__init__.py +102 -0
- workflow_core-1.4.0/workflow/lifecycle/archive/http.py +58 -0
- workflow_core-1.4.0/workflow/lifecycle/archive/posix.py +185 -0
- workflow_core-1.4.0/workflow/lifecycle/archive/s3.py +157 -0
- workflow_core-1.4.0/workflow/lifecycle/attempt.py +112 -0
- workflow_core-1.4.0/workflow/lifecycle/configure.py +152 -0
- workflow_core-1.4.0/workflow/lifecycle/execute.py +159 -0
- workflow_core-1.4.0/workflow/utils/__init__.py +0 -0
- workflow_core-1.4.0/workflow/utils/decorators.py +29 -0
- workflow_core-1.4.0/workflow/utils/logger.py +93 -0
- workflow_core-1.4.0/workflow/utils/prompt.py +26 -0
- workflow_core-1.4.0/workflow/utils/read.py +146 -0
- workflow_core-1.4.0/workflow/utils/renderers.py +113 -0
- workflow_core-1.4.0/workflow/utils/tmate.sh +17 -0
- workflow_core-1.4.0/workflow/utils/validate.py +198 -0
- workflow_core-1.4.0/workflow/utils/variables.py +24 -0
- workflow_core-1.4.0/workflow/utils/write.py +44 -0
- workflow_core-1.4.0/workflow/workspaces/__init__.py +0 -0
- workflow_core-1.4.0/workflow/workspaces/chimefrb.yml +48 -0
- workflow_core-1.4.0/workflow/workspaces/development.yml +48 -0
- workflow_core-1.4.0/workflow/workspaces/site-dev.yml +36 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: workflow.core
|
|
3
|
+
Version: 1.4.0
|
|
4
|
+
Summary: Workflow Core
|
|
5
|
+
Home-page: https://github.com/chimefrb/workflow
|
|
6
|
+
License: MIT
|
|
7
|
+
Author: Shiny Brar
|
|
8
|
+
Author-email: charanjotbrar@gmail.com
|
|
9
|
+
Requires-Python: >=3.8.1,<4.0
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Requires-Dist: click (>=8.1,<9.0)
|
|
17
|
+
Requires-Dist: click-params (>=0.5,<0.6)
|
|
18
|
+
Requires-Dist: docker (>=7.1,<8.0)
|
|
19
|
+
Requires-Dist: minio (>=7.2,<8.0)
|
|
20
|
+
Requires-Dist: pydantic (>=2.0,<3.0)
|
|
21
|
+
Requires-Dist: pydantic-settings (>=2.0,<3.0)
|
|
22
|
+
Requires-Dist: python-logging-loki (>=0.3,<0.4)
|
|
23
|
+
Requires-Dist: pyyaml (>=6.0,<7.0)
|
|
24
|
+
Requires-Dist: requests (>=2.31,<3.0)
|
|
25
|
+
Requires-Dist: rich (>=13.4,<14.0)
|
|
26
|
+
Requires-Dist: tenacity (>=8.2,<9.0)
|
|
27
|
+
Requires-Dist: toml (>=0.10,<0.11)
|
|
28
|
+
Project-URL: Documentation, https://chimefrb.github.io/workflow-docs/
|
|
29
|
+
Project-URL: Repository, https://github.com/chimefrb/workflow
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
[](https://github.com/CHIMEFRB/workflow/actions/workflows/ci.yml) [](https://github.com/CHIMEFRB/workflow/actions/workflows/cd.yml) [](https://coveralls.io/github/CHIMEFRB/workflow?branch=main)
|
|
33
|
+
|
|
34
|
+
# Workflow
|
|
35
|
+
|
|
36
|
+
Workflow is a Python-based system designed to manage and automate any task in a structured manner. It provides a framework for defining (work), scheduling (buckets), sequencing (pipelines), executing (managers) and archiving (results) the output of any task. The system is designed to be modular with a low threshold of entry for new users, while also providing advanced features for power users.
|
|
37
|
+
|
|
38
|
+
For more information, please refer to the [Workflow documentation](https://chimefrb.github.io/workflow-docs/).
|
|
39
|
+
|
|
40
|
+
## Getting Started
|
|
41
|
+
|
|
42
|
+
To get started with the Workflow project, you need to have Python 3.8.1 or later installed. You can then install the project's dependencies using Poetry:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
git clone https://github.com/chimefrb/workflow.git
|
|
46
|
+
cd workflow
|
|
47
|
+
poetry install
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Alternatively, you can add the Workflow project as a dependency to your own project using Poetry:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
poetry add git+https://github.chime/chimefrb/workflow.git
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Contributing
|
|
57
|
+
|
|
58
|
+
Contributions to the Workflow project are welcome. Please ensure that any changes you make pass the project's tests and adhere to the project's coding standards.
|
|
59
|
+
|
|
60
|
+
### Setting Up Your Development Environment
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
git clone https://github.com/chimefrb/workflow.git
|
|
64
|
+
cd workflow
|
|
65
|
+
poetry install
|
|
66
|
+
pre-commit install
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Writing Your First Commit
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
git add file/you/changed.py
|
|
73
|
+
poetry run commitizen commit
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Running Tests
|
|
77
|
+
|
|
78
|
+
You can run the project's tests using Docker & Poetry:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
docker compose up -d
|
|
82
|
+
poetry run pytest
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
Workflow is licensed under the MIT license.
|
|
88
|
+
|
|
89
|
+
Copyright (c) 2024 CHIME/FRB Collaboration
|
|
90
|
+
|
|
91
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
92
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
93
|
+
in the Software without restriction, including without limitation the rights
|
|
94
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
95
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
96
|
+
furnished to do so, subject to the following conditions:
|
|
97
|
+
|
|
98
|
+
The above copyright notice and this permission notice shall be included in all
|
|
99
|
+
copies or substantial portions of the Software.
|
|
100
|
+
|
|
101
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
102
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
103
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
104
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
105
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
106
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
107
|
+
SOFTWARE.
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
<p align="center">
|
|
111
|
+
<a href="Some Love">
|
|
112
|
+
<img src="https://forthebadge.com/images/badges/built-with-love.svg">
|
|
113
|
+
</a>
|
|
114
|
+
</p>
|
|
115
|
+
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
[](https://github.com/CHIMEFRB/workflow/actions/workflows/ci.yml) [](https://github.com/CHIMEFRB/workflow/actions/workflows/cd.yml) [](https://coveralls.io/github/CHIMEFRB/workflow?branch=main)
|
|
2
|
+
|
|
3
|
+
# Workflow
|
|
4
|
+
|
|
5
|
+
Workflow is a Python-based system designed to manage and automate any task in a structured manner. It provides a framework for defining (work), scheduling (buckets), sequencing (pipelines), executing (managers) and archiving (results) the output of any task. The system is designed to be modular with a low threshold of entry for new users, while also providing advanced features for power users.
|
|
6
|
+
|
|
7
|
+
For more information, please refer to the [Workflow documentation](https://chimefrb.github.io/workflow-docs/).
|
|
8
|
+
|
|
9
|
+
## Getting Started
|
|
10
|
+
|
|
11
|
+
To get started with the Workflow project, you need to have Python 3.8.1 or later installed. You can then install the project's dependencies using Poetry:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
git clone https://github.com/chimefrb/workflow.git
|
|
15
|
+
cd workflow
|
|
16
|
+
poetry install
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Alternatively, you can add the Workflow project as a dependency to your own project using Poetry:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
poetry add git+https://github.chime/chimefrb/workflow.git
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Contributing
|
|
26
|
+
|
|
27
|
+
Contributions to the Workflow project are welcome. Please ensure that any changes you make pass the project's tests and adhere to the project's coding standards.
|
|
28
|
+
|
|
29
|
+
### Setting Up Your Development Environment
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
git clone https://github.com/chimefrb/workflow.git
|
|
33
|
+
cd workflow
|
|
34
|
+
poetry install
|
|
35
|
+
pre-commit install
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Writing Your First Commit
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
git add file/you/changed.py
|
|
42
|
+
poetry run commitizen commit
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Running Tests
|
|
46
|
+
|
|
47
|
+
You can run the project's tests using Docker & Poetry:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
docker compose up -d
|
|
51
|
+
poetry run pytest
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## License
|
|
55
|
+
|
|
56
|
+
Workflow is licensed under the MIT license.
|
|
57
|
+
|
|
58
|
+
Copyright (c) 2024 CHIME/FRB Collaboration
|
|
59
|
+
|
|
60
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
61
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
62
|
+
in the Software without restriction, including without limitation the rights
|
|
63
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
64
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
65
|
+
furnished to do so, subject to the following conditions:
|
|
66
|
+
|
|
67
|
+
The above copyright notice and this permission notice shall be included in all
|
|
68
|
+
copies or substantial portions of the Software.
|
|
69
|
+
|
|
70
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
71
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
72
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
73
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
74
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
75
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
76
|
+
SOFTWARE.
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
<p align="center">
|
|
80
|
+
<a href="Some Love">
|
|
81
|
+
<img src="https://forthebadge.com/images/badges/built-with-love.svg">
|
|
82
|
+
</a>
|
|
83
|
+
</p>
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "workflow.core"
|
|
3
|
+
version = "1.4.0"
|
|
4
|
+
description = "Workflow Core"
|
|
5
|
+
authors = ["Shiny Brar <charanjotbrar@gmail.com>"]
|
|
6
|
+
license = "MIT"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
repository = "https://github.com/chimefrb/workflow"
|
|
9
|
+
documentation = "https://chimefrb.github.io/workflow-docs/"
|
|
10
|
+
packages = [
|
|
11
|
+
{ include = "workflow", from = "." }
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[tool.poetry.dependencies]
|
|
15
|
+
python = ">=3.8.1,<4.0"
|
|
16
|
+
tenacity = "^8.2"
|
|
17
|
+
pydantic = "^2.0"
|
|
18
|
+
requests = "^2.31"
|
|
19
|
+
pyyaml = "^6.0"
|
|
20
|
+
click = "^8.1"
|
|
21
|
+
toml = "^0.10"
|
|
22
|
+
rich = "^13.4"
|
|
23
|
+
minio = "^7.2"
|
|
24
|
+
pydantic-settings = "^2.0"
|
|
25
|
+
python-logging-loki = "^0.3"
|
|
26
|
+
click-params = "^0.5"
|
|
27
|
+
docker = "^7.1"
|
|
28
|
+
|
|
29
|
+
[tool.poetry.group.dev.dependencies]
|
|
30
|
+
mypy = "*"
|
|
31
|
+
pytest = "*"
|
|
32
|
+
pytest-cov = "*"
|
|
33
|
+
tomli = "*"
|
|
34
|
+
pre-commit = "*"
|
|
35
|
+
types-requests = "*"
|
|
36
|
+
types-toml = "*"
|
|
37
|
+
types-setuptools = "*"
|
|
38
|
+
types-pyyaml = "*"
|
|
39
|
+
pytest-env = "*"
|
|
40
|
+
ruff = "*"
|
|
41
|
+
commitizen = "*"
|
|
42
|
+
|
|
43
|
+
[tool.poetry.scripts]
|
|
44
|
+
workflow = "workflow.cli.main:cli"
|
|
45
|
+
|
|
46
|
+
[build-system]
|
|
47
|
+
requires = ["poetry-core"]
|
|
48
|
+
build-backend = "poetry.core.masonry.api"
|
|
49
|
+
|
|
50
|
+
# Pytest Environment Variables
|
|
51
|
+
[tool.pytest.ini_options]
|
|
52
|
+
env = [
|
|
53
|
+
"WORKFLOW_S3_ENDPOINT=play.min.io",
|
|
54
|
+
"WORKFLOW_S3_ACCESS_KEY=Q3AM3UQ867SPQQA43P2F",
|
|
55
|
+
"WORKFLOW_S3_SECRET_KEY=zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"
|
|
56
|
+
]
|
|
@@ -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}
|
|
File without changes
|
|
@@ -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
|
|
@@ -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)
|