workflow.core 1.4.0__tar.gz → 1.5.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.
Files changed (57) hide show
  1. {workflow_core-1.4.0 → workflow_core-1.5.0}/PKG-INFO +11 -5
  2. {workflow_core-1.4.0 → workflow_core-1.5.0}/README.md +10 -4
  3. {workflow_core-1.4.0 → workflow_core-1.5.0}/pyproject.toml +1 -1
  4. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/daemons/audit.py +10 -1
  5. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/daemons/transfer.py +44 -89
  6. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/lifecycle/archive/s3.py +6 -6
  7. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/__init__.py +0 -0
  8. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/cli/__init__.py +0 -0
  9. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/cli/buckets.py +0 -0
  10. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/cli/configs.py +0 -0
  11. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/cli/main.py +0 -0
  12. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/cli/pipelines.py +0 -0
  13. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/cli/results.py +0 -0
  14. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/cli/run.py +0 -0
  15. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/cli/schedules.py +0 -0
  16. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/cli/workspace.py +0 -0
  17. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/daemons/__init__.py +0 -0
  18. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/definitions/__init__.py +0 -0
  19. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/definitions/config.py +0 -0
  20. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/definitions/jsonschema.md +0 -0
  21. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/definitions/notify.py +0 -0
  22. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/definitions/work.py +0 -0
  23. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/definitions/workspace.py +0 -0
  24. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/examples/function.py +0 -0
  25. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/examples/sample.svg +0 -0
  26. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/examples/sample.workflow.yml +0 -0
  27. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/helpers/__init__.py +0 -0
  28. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/helpers/date.py +0 -0
  29. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/http/__init__.py +0 -0
  30. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/http/buckets.py +0 -0
  31. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/http/client.py +0 -0
  32. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/http/configs.py +0 -0
  33. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/http/context.py +0 -0
  34. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/http/pipelines.py +0 -0
  35. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/http/results.py +0 -0
  36. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/http/schedules.py +0 -0
  37. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/lifecycle/__init__.py +0 -0
  38. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/lifecycle/archive/__init__.py +0 -0
  39. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/lifecycle/archive/http.py +0 -0
  40. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/lifecycle/archive/posix.py +0 -0
  41. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/lifecycle/attempt.py +0 -0
  42. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/lifecycle/configure.py +0 -0
  43. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/lifecycle/execute.py +0 -0
  44. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/utils/__init__.py +0 -0
  45. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/utils/decorators.py +0 -0
  46. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/utils/logger.py +0 -0
  47. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/utils/prompt.py +0 -0
  48. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/utils/read.py +0 -0
  49. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/utils/renderers.py +0 -0
  50. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/utils/tmate.sh +0 -0
  51. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/utils/validate.py +0 -0
  52. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/utils/variables.py +0 -0
  53. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/utils/write.py +0 -0
  54. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/workspaces/__init__.py +0 -0
  55. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/workspaces/chimefrb.yml +0 -0
  56. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/workspaces/development.yml +0 -0
  57. {workflow_core-1.4.0 → workflow_core-1.5.0}/workflow/workspaces/site-dev.yml +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: workflow.core
3
- Version: 1.4.0
3
+ Version: 1.5.0
4
4
  Summary: Workflow Core
5
5
  Home-page: https://github.com/chimefrb/workflow
6
6
  License: MIT
@@ -39,12 +39,18 @@ For more information, please refer to the [Workflow documentation](https://chime
39
39
 
40
40
  ## Getting Started
41
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:
42
+ To get started with the Workflow, you need to have Python 3.8.1 or later installed. You can then install the project's dependencies using Poetry:
43
+
44
+ ### Install from PyPI
43
45
 
44
46
  ```bash
45
- git clone https://github.com/chimefrb/workflow.git
46
- cd workflow
47
- poetry install
47
+ pip install workflow.core
48
+ ```
49
+
50
+ ### Install from Source
51
+
52
+ ```bash
53
+ pip install git+https://github.com/chimefrb/workflow.git
48
54
  ```
49
55
 
50
56
  Alternatively, you can add the Workflow project as a dependency to your own project using Poetry:
@@ -8,12 +8,18 @@ For more information, please refer to the [Workflow documentation](https://chime
8
8
 
9
9
  ## Getting Started
10
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:
11
+ To get started with the Workflow, you need to have Python 3.8.1 or later installed. You can then install the project's dependencies using Poetry:
12
+
13
+ ### Install from PyPI
12
14
 
13
15
  ```bash
14
- git clone https://github.com/chimefrb/workflow.git
15
- cd workflow
16
- poetry install
16
+ pip install workflow.core
17
+ ```
18
+
19
+ ### Install from Source
20
+
21
+ ```bash
22
+ pip install git+https://github.com/chimefrb/workflow.git
17
23
  ```
18
24
 
19
25
  Alternatively, you can add the Workflow project as a dependency to your own project using Poetry:
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "workflow.core"
3
- version = "1.4.0"
3
+ version = "1.5.0"
4
4
  description = "Workflow Core"
5
5
  authors = ["Shiny Brar <charanjotbrar@gmail.com>"]
6
6
  license = "MIT"
@@ -1,7 +1,7 @@
1
1
  """Audit Daemon."""
2
2
 
3
3
  import time
4
- from typing import Any, Dict, Union
4
+ from typing import Any, Dict, Optional, Union
5
5
 
6
6
  import click
7
7
  from click_params import JSON, URL, FirstOf
@@ -34,6 +34,13 @@ logger = get_logger("workflow.daemons.audit")
34
34
  show_default=True,
35
35
  help="workspace config.",
36
36
  )
37
+ @click.option(
38
+ "--token",
39
+ "-t",
40
+ default=None,
41
+ type=click.STRING,
42
+ help="Authentication Token.",
43
+ )
37
44
  @click.option(
38
45
  "--test-mode",
39
46
  default=False,
@@ -44,6 +51,7 @@ logger = get_logger("workflow.daemons.audit")
44
51
  def audit(
45
52
  sleep: int,
46
53
  workspace: Union[str, Dict[Any, Any]],
54
+ token: Optional[str],
47
55
  test_mode: bool,
48
56
  ) -> Dict[str, Any]:
49
57
  """Audit Buckets Backend.
@@ -60,6 +68,7 @@ def audit(
60
68
  logger.info("Starting Audit Daemon")
61
69
  logger.info(f"Sleep Time: {sleep}")
62
70
  logger.info(f"Workspace : {workspace}")
71
+ logger.info(f"Token : {token}")
63
72
  logger.info(f"Test Mode : {test_mode}")
64
73
  configure.workspace(workspace=workspace)
65
74
 
@@ -1,19 +1,16 @@
1
1
  """Workflow Transfer Daemon."""
2
2
 
3
3
  import time
4
- from typing import Any, Dict, List, Union
4
+ from typing import Any, Dict, List
5
5
 
6
6
  import click
7
- from click_params import JSON, URL, FirstOf
7
+
8
8
  from workflow import DEFAULT_WORKSPACE_PATH
9
9
  from workflow.http.buckets import Buckets
10
10
  from workflow.http.results import Results
11
- from workflow.utils.logger import get_logger
12
- from workflow.utils import read
13
- from workflow.lifecycle import configure
14
- from workflow.http.context import HTTPContext
11
+ from workflow.utils import logger, read
15
12
 
16
- logger = get_logger("workflow.daemons.transfer")
13
+ log = logger.get_logger("workflow.daemons.transfer")
17
14
 
18
15
 
19
16
  def deposit_work_to_results(
@@ -66,94 +63,48 @@ def is_work_already_deposited(results: Results, work: Dict[str, Any]) -> bool:
66
63
 
67
64
 
68
65
  @click.command()
69
- @click.option("--sleep", "-s", default=5, help="seconds to sleep between transfers.")
66
+ @click.option("--sleep", "-s", default=5, help="Time to sleep between transfers")
70
67
  @click.option(
71
- "-w",
72
- "--workspace",
73
- type=FirstOf(
74
- click.Path(exists=True, file_okay=True, dir_okay=False, resolve_path=True),
75
- URL,
76
- JSON,
77
- ),
78
- default=(DEFAULT_WORKSPACE_PATH.as_posix()),
79
- show_default=True,
80
- help="workspace config.",
68
+ "--buckets-base-url",
69
+ "-b",
70
+ default="http://frb-vsop.chime:8004",
71
+ help="Location of the Buckets backend.",
81
72
  )
82
- @click.option("--limit", default=50, help="works to transfer per run.")
83
73
  @click.option(
84
- "--cutoff", default=60 * 60 * 24 * 7, help="cutoff time in seconds for stale work."
74
+ "--results-base-url",
75
+ "-r",
76
+ default="http://frb-vsop.chime:8005",
77
+ help="Location of the Results backend.",
85
78
  )
86
79
  @click.option(
87
80
  "--test-mode", default=False, help="Enable test mode to avoid while True loop"
88
81
  )
89
- def transfer(
82
+ def transfer_work(
90
83
  sleep: int,
91
- workspace: Union[str, Dict[Any, Any]],
84
+ buckets_base_url: str,
85
+ results_base_url: str,
92
86
  test_mode: bool,
93
- limit: int,
94
- cutoff: int,
87
+ limit_per_run: int = 50,
95
88
  ) -> Dict[str, Any]:
96
- """Transfer work from Buckets to Results.
97
- Args:
98
- sleep (int): seconds to sleep between transfers.
99
- workspace (Union[str, Dict[Any, Any]]): workspace config.
100
- test_mode (bool): Enable test mode to avoid while True loop.
101
- limit (int): works to transfer per run.
102
- cutoff (int): cutoff time in seconds for stale work.
89
+ """Transfer successful Work from Buckets DB to Results DB.
103
90
 
104
- Returns:
105
- Dict[str, Any]: _description_
91
+ Args:
92
+ sleep (int): number of seconds to sleep between transfers
93
+ buckets_base_url (str): location of the Buckets backend
94
+ results_base_url (str): location of the Results backend
95
+ test_mode (bool): Enable test mode to avoid while True loop
96
+ limit_per_run (int): Max number of failed Work entires to transfer per
97
+ run of daemon.
106
98
  """
107
- logger.info("Starting Transfer Daemon")
108
- logger.info(f"Sleep Time: {sleep}")
109
- logger.info(f"Workspace : {workspace}")
110
- logger.info(f"Test Mode : {test_mode}")
111
- logger.info(f"Limit/Tx : {limit}")
112
- logger.info(f"Cutoff : {cutoff} days")
113
- configure.workspace(workspace=workspace)
114
- archive: bool = (
115
- read.workspace(DEFAULT_WORKSPACE_PATH.as_posix())
116
- .get("config", {})
117
- .get("archive", {})
118
- .get("results", True)
119
- )
120
- logger.info(f"Archive : {'Enabled' if archive else 'Disabled'}")
121
- http: HTTPContext = HTTPContext(backends=["buckets", "results"])
122
- logger.info("HTTP Context Initialized")
123
- logger.info(f"HTTP Context: Buckets Backend @ {http.buckets.baseurl}")
124
- logger.info(f"HTTP Context: Results Backend @ {http.results.baseurl}")
125
-
126
- delete: List[str] = []
127
- successful: List[Dict[str, Any]] = []
128
- failed: List[Dict[str, Any]] = []
129
-
130
- for work in http.buckets.view(
131
- query={"status": "success"}, projection={}, skip=0, limit=limit
132
- ):
133
- if work["config"]["archive"]["results"] is False:
134
- delete.append(work["id"])
135
- elif work["config"]["archive"]["results"] is True and archive:
136
- successful.append(work)
137
- else:
138
- delete.append(work["id"])
139
-
140
- # Transfer successful work to results
141
- response: Dict[str, Any] = {}
142
- response = http.results.deposit(successful)
143
- for key, value in response.items():
144
- if value:
145
- delete.append(key)
146
-
147
- try:
148
- logger.info(f"Transferring {len(successful)} successful works to results")
149
- response = http.results.deposit(successful)
150
- for key, value in response.items():
151
- if value:
152
- delete.append(key)
153
- except Exception as error:
154
- logger.error("Failed to deposit successful works to results")
155
- logger.error(f"Exception: {error}")
156
-
99
+ buckets = Buckets(base_url=buckets_base_url, debug=test_mode)
100
+ results = Results(base_url=results_base_url, debug=test_mode)
101
+
102
+ log.info("Starting Transfer Daemon")
103
+ log.info(f"Sleeptime: {sleep}")
104
+ log.info(f"Buckets@ : {buckets_base_url}")
105
+ log.info(f"Results@ : {results_base_url}")
106
+ log.info(f"Test Mode: {test_mode}")
107
+ log.info(f"Limit/Tx : {limit_per_run}")
157
108
 
158
109
  def transfer(test_flag: bool, buckets: Buckets, results: Results) -> Dict[str, Any]:
159
110
  """Transfer Work from Buckets to Results.
@@ -166,7 +117,12 @@ def transfer(
166
117
  Returns:
167
118
  Dict[str, Any]: Transfer status.
168
119
  """
169
-
120
+ results_workspace_config = (
121
+ read.workspace(DEFAULT_WORKSPACE_PATH.as_posix())
122
+ .get("config", {})
123
+ .get("archive", {})
124
+ .get("results", None)
125
+ )
170
126
  transfer_status: Dict[str, Any] = {}
171
127
  # 1. Transfer successful Work
172
128
  # TODO: decide projection fields
@@ -174,7 +130,7 @@ def transfer(
174
130
  query={"status": "success"},
175
131
  projection={},
176
132
  skip=0,
177
- limit=limit,
133
+ limit=limit_per_run,
178
134
  )
179
135
  successful_work_to_delete = [
180
136
  work
@@ -187,7 +143,6 @@ def transfer(
187
143
  for work in successful_work
188
144
  if work["config"]["archive"]["results"] is True and results_workspace_config
189
145
  ]
190
-
191
146
  if successful_work_to_transfer:
192
147
  transfer_status["successful_work_transferred"] = deposit_work_to_results(
193
148
  buckets, results, successful_work_to_transfer
@@ -206,7 +161,7 @@ def transfer(
206
161
  },
207
162
  projection={},
208
163
  skip=0,
209
- limit=limit,
164
+ limit=limit_per_run,
210
165
  )
211
166
  failed_work_to_delete = [
212
167
  work
@@ -236,7 +191,7 @@ def transfer(
236
191
  },
237
192
  projection={},
238
193
  skip=0,
239
- limit=limit,
194
+ limit=limit_per_run,
240
195
  )
241
196
  if stale_work:
242
197
  buckets.delete_ids([work["id"] for work in stale_work])
@@ -252,4 +207,4 @@ def transfer(
252
207
 
253
208
 
254
209
  if __name__ == "__main__":
255
- transfer()
210
+ transfer_work()
@@ -68,9 +68,9 @@ def copy(path: Path, payload: Optional[List[str]]) -> bool:
68
68
  file_path=item,
69
69
  )
70
70
  # Update payload with new path
71
- payload[
72
- index
73
- ] = f"s3://{os.getenv('WORKFLOW_S3_ENDPOINT')}/workflow/{'/'.join([object_paths, item.split('/')[-1]])}" # noqa: E501
71
+ payload[index] = (
72
+ f"s3://{os.getenv('WORKFLOW_S3_ENDPOINT')}/workflow/{'/'.join([object_paths, item.split('/')[-1]])}" # noqa: E501
73
+ )
74
74
  log.info("Move complete ✅")
75
75
  return True
76
76
  except Exception as error:
@@ -120,9 +120,9 @@ def move(path: Path, payload: Optional[List[str]]) -> bool:
120
120
  file_path=item,
121
121
  )
122
122
  # Update payload with new path
123
- payload[
124
- index
125
- ] = f"s3://{os.getenv('WORKFLOW_S3_ENDPOINT')}/workflow/{'/'.join([object_paths, item.split('/')[-1]])}" # noqa: E501 # noqa: E501
123
+ payload[index] = (
124
+ f"s3://{os.getenv('WORKFLOW_S3_ENDPOINT')}/workflow/{'/'.join([object_paths, item.split('/')[-1]])}" # noqa: E501 # noqa: E501
125
+ )
126
126
  # Delete file
127
127
  os.remove(item)
128
128
  log.info("Move complete ✅")