dagster-ray 0.0.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.
- dagster_ray-0.0.0/LICENSE +201 -0
- dagster_ray-0.0.0/PKG-INFO +44 -0
- dagster_ray-0.0.0/README.md +18 -0
- dagster_ray-0.0.0/dagster_ray/__init__.py +5 -0
- dagster_ray-0.0.0/dagster_ray/_version.py +1 -0
- dagster_ray-0.0.0/dagster_ray/configs.py +13 -0
- dagster_ray-0.0.0/dagster_ray/executor.py +384 -0
- dagster_ray-0.0.0/dagster_ray/executor_2.py +284 -0
- dagster_ray-0.0.0/dagster_ray/io_managers.py +38 -0
- dagster_ray-0.0.0/dagster_ray/py.typed +0 -0
- dagster_ray-0.0.0/dagster_ray/resource.py +55 -0
- dagster_ray-0.0.0/pyproject.toml +155 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2023 Elementl, Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: dagster-ray
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: Dagster integration library for Ray
|
|
5
|
+
Home-page: https://github.com/danielgafni/dagster-ray
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Keywords: dagster,ray,ETL,distributed
|
|
8
|
+
Author: Daniel Gafni
|
|
9
|
+
Author-email: danielgafni16@gmail.com
|
|
10
|
+
Requires-Python: >=3.8,<4.0
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Requires-Dist: dagster (>=1.3.5,<2.0.0)
|
|
20
|
+
Requires-Dist: dagster-k8s (>=0.20.10,<0.21.0)
|
|
21
|
+
Requires-Dist: pyarrow (>=8.0.0)
|
|
22
|
+
Requires-Dist: ray (>=2.6.3,<3.0.0)
|
|
23
|
+
Project-URL: Repository, https://github.com/danielgafni/dagster-ray
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# `dagster-ray`
|
|
27
|
+
|
|
28
|
+
[Ray](https://github.com/ray-project/ray) integration library for [Dagster](https://github.com/dagster-io/dagster).
|
|
29
|
+
|
|
30
|
+
> [!WARNING]
|
|
31
|
+
> WIP, perhaps not usable.
|
|
32
|
+
|
|
33
|
+
# Features
|
|
34
|
+
|
|
35
|
+
## Resource
|
|
36
|
+
|
|
37
|
+
`RayResource` provides access to a Ray cluster from within a Dagster pipeline.
|
|
38
|
+
|
|
39
|
+
## IOManagers
|
|
40
|
+
WIP
|
|
41
|
+
|
|
42
|
+
## Executor
|
|
43
|
+
WIP
|
|
44
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# `dagster-ray`
|
|
2
|
+
|
|
3
|
+
[Ray](https://github.com/ray-project/ray) integration library for [Dagster](https://github.com/dagster-io/dagster).
|
|
4
|
+
|
|
5
|
+
> [!WARNING]
|
|
6
|
+
> WIP, perhaps not usable.
|
|
7
|
+
|
|
8
|
+
# Features
|
|
9
|
+
|
|
10
|
+
## Resource
|
|
11
|
+
|
|
12
|
+
`RayResource` provides access to a Ray cluster from within a Dagster pipeline.
|
|
13
|
+
|
|
14
|
+
## IOManagers
|
|
15
|
+
WIP
|
|
16
|
+
|
|
17
|
+
## Executor
|
|
18
|
+
WIP
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.0.0" # this field is managed by poetry-dynamic-versioning
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from typing import List, Optional
|
|
2
|
+
|
|
3
|
+
from dagster import Config
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ContainerConfig(Config):
|
|
7
|
+
image: Optional[str] = None
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class RuntimeEnvConfig(Config):
|
|
11
|
+
working_dir: Optional[str] = None
|
|
12
|
+
pip: Optional[List[str]] = None
|
|
13
|
+
container: Optional[ContainerConfig] = None
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
# import multiprocessing
|
|
2
|
+
# import os
|
|
3
|
+
# import socket
|
|
4
|
+
# from pathlib import Path
|
|
5
|
+
# from typing import Optional, Dict, Any
|
|
6
|
+
#
|
|
7
|
+
# import ray
|
|
8
|
+
# from dagster import Field, MetadataEntry, Noneable
|
|
9
|
+
# from dagster import _check as check
|
|
10
|
+
# from dagster import executor, InitExecutorContext
|
|
11
|
+
# from dagster._core.errors import (
|
|
12
|
+
# DagsterExecutionInterruptedError,
|
|
13
|
+
# DagsterSubprocessError,
|
|
14
|
+
# )
|
|
15
|
+
# from dagster._core.events import DagsterEvent, EngineEventData
|
|
16
|
+
# from dagster._core.execution.api import create_execution_plan, execute_plan_iterator
|
|
17
|
+
# from dagster._core.execution.context.system import PlanOrchestrationContext
|
|
18
|
+
# from dagster._core.execution.context_creation_job import create_context_free_log_manager
|
|
19
|
+
# from dagster._core.execution.plan.plan import ExecutionPlan
|
|
20
|
+
# from dagster._core.execution.retries import RetryMode
|
|
21
|
+
# from dagster._core.executor.base import Executor
|
|
22
|
+
# from dagster._core.instance import DagsterInstance
|
|
23
|
+
# from dagster._utils.timing import format_duration, time_execution_scope
|
|
24
|
+
# from ray import remote
|
|
25
|
+
#
|
|
26
|
+
#
|
|
27
|
+
# RAY_TIMEOUT = 1
|
|
28
|
+
#
|
|
29
|
+
#
|
|
30
|
+
# @remote(num_cpus=1) # TODO configurable per step
|
|
31
|
+
# class RayProcessCommand:
|
|
32
|
+
# def __init__(
|
|
33
|
+
# self,
|
|
34
|
+
# run_config,
|
|
35
|
+
# pipeline_run,
|
|
36
|
+
# instance_ref,
|
|
37
|
+
# step_key,
|
|
38
|
+
# recon_pipeline,
|
|
39
|
+
# retry_mode,
|
|
40
|
+
# known_state,
|
|
41
|
+
# ):
|
|
42
|
+
# self.run_config = run_config
|
|
43
|
+
# self.pipeline_run = pipeline_run
|
|
44
|
+
# self.instance_ref = instance_ref
|
|
45
|
+
#
|
|
46
|
+
# self.step_key = step_key
|
|
47
|
+
# self.recon_pipeline = recon_pipeline
|
|
48
|
+
# self.retry_mode = retry_mode
|
|
49
|
+
# self.known_state = known_state
|
|
50
|
+
#
|
|
51
|
+
# self.events = []
|
|
52
|
+
# self.execution_complete = False
|
|
53
|
+
#
|
|
54
|
+
# def heartbeat(self):
|
|
55
|
+
# return True
|
|
56
|
+
#
|
|
57
|
+
# def get_events(self):
|
|
58
|
+
# return self.events
|
|
59
|
+
#
|
|
60
|
+
# def start(self):
|
|
61
|
+
# for event in self.execute():
|
|
62
|
+
# self.events.append(event)
|
|
63
|
+
#
|
|
64
|
+
# return True
|
|
65
|
+
#
|
|
66
|
+
# def next(self):
|
|
67
|
+
# if self.events:
|
|
68
|
+
# return self.events.pop(0)
|
|
69
|
+
# return None
|
|
70
|
+
#
|
|
71
|
+
# def execute(self):
|
|
72
|
+
# pipeline = self.recon_pipeline
|
|
73
|
+
# with DagsterInstance.from_ref(self.instance_ref) as instance:
|
|
74
|
+
# execution_plan = create_execution_plan(
|
|
75
|
+
# pipeline=pipeline,
|
|
76
|
+
# run_config=self.run_config,
|
|
77
|
+
# mode=self.pipeline_run.mode,
|
|
78
|
+
# step_keys_to_execute=[self.step_key],
|
|
79
|
+
# known_state=self.known_state,
|
|
80
|
+
# )
|
|
81
|
+
#
|
|
82
|
+
# log_manager = create_context_free_log_manager(instance, self.pipeline_run)
|
|
83
|
+
#
|
|
84
|
+
# yield DagsterEvent.step_worker_started(
|
|
85
|
+
# log_manager,
|
|
86
|
+
# self.pipeline_run.pipeline_name,
|
|
87
|
+
# # TODO modify to make sense in ray context
|
|
88
|
+
# message='Executing step "{}" in subprocess.'.format(self.step_key),
|
|
89
|
+
# metadata_entries=[
|
|
90
|
+
# MetadataEntry("pid", value=str(os.getpid())),
|
|
91
|
+
# ],
|
|
92
|
+
# step_key=self.step_key,
|
|
93
|
+
# )
|
|
94
|
+
#
|
|
95
|
+
# try:
|
|
96
|
+
# yield from execute_plan_iterator(
|
|
97
|
+
# execution_plan,
|
|
98
|
+
# pipeline,
|
|
99
|
+
# self.pipeline_run,
|
|
100
|
+
# run_config=self.run_config,
|
|
101
|
+
# retry_mode=self.retry_mode.for_inner_plan(),
|
|
102
|
+
# instance=instance,
|
|
103
|
+
# )
|
|
104
|
+
# except:
|
|
105
|
+
# raise ValueError()
|
|
106
|
+
# yield (1, 1, 1)
|
|
107
|
+
#
|
|
108
|
+
#
|
|
109
|
+
# class RayExecutor(Executor):
|
|
110
|
+
# def __init__(
|
|
111
|
+
# self,
|
|
112
|
+
# retries: RetryMode,
|
|
113
|
+
# max_concurrent: int,
|
|
114
|
+
# resources: Optional[Dict[str, Any]] = None
|
|
115
|
+
# ):
|
|
116
|
+
# self._retries = check.inst_param(retries, "retries", RetryMode)
|
|
117
|
+
# max_concurrent = max_concurrent if max_concurrent else multiprocessing.cpu_count() # TODO whats smart?
|
|
118
|
+
# self._max_concurrent = check.int_param(max_concurrent, "max_concurrent")
|
|
119
|
+
#
|
|
120
|
+
# resources = resources if resources is not None else {}
|
|
121
|
+
# self._resources = resources.copy()
|
|
122
|
+
#
|
|
123
|
+
# @property
|
|
124
|
+
# def retries(self):
|
|
125
|
+
# return self._retries
|
|
126
|
+
#
|
|
127
|
+
# def execute(self, plan_context, execution_plan):
|
|
128
|
+
# check.inst_param(plan_context, "plan_context", PlanOrchestrationContext)
|
|
129
|
+
# check.inst_param(execution_plan, "execution_plan", ExecutionPlan)
|
|
130
|
+
#
|
|
131
|
+
# pipeline = plan_context.reconstructable_pipeline
|
|
132
|
+
# limit = self._max_concurrent
|
|
133
|
+
# host = socket.gethostname()
|
|
134
|
+
# yield DagsterEvent.engine_event(
|
|
135
|
+
# plan_context,
|
|
136
|
+
# f"Executing steps using ray executor: driver host ({host})",
|
|
137
|
+
# ## TODO: change?
|
|
138
|
+
# event_specific_data=EngineEventData.multiprocess(
|
|
139
|
+
# host, step_keys_to_execute=execution_plan.step_keys_to_execute
|
|
140
|
+
# ),
|
|
141
|
+
# )
|
|
142
|
+
#
|
|
143
|
+
# # It would be good to implement a reference tracking algorithm here so we could
|
|
144
|
+
# # garbage collect results that are no longer needed by any steps
|
|
145
|
+
# # https://github.com/dagster-io/dagster/issues/811
|
|
146
|
+
# with time_execution_scope() as timer_result:
|
|
147
|
+
# with execution_plan.start(retry_mode=self.retries) as active_execution:
|
|
148
|
+
# active_iters = {}
|
|
149
|
+
# actors = {}
|
|
150
|
+
# stopping = False
|
|
151
|
+
#
|
|
152
|
+
# while (not stopping and not active_execution.is_complete) or active_iters:
|
|
153
|
+
# if active_execution.check_for_interrupts():
|
|
154
|
+
# step_keys, active_actors = zip(*actors.items())
|
|
155
|
+
# yield DagsterEvent.engine_event(
|
|
156
|
+
# plan_context,
|
|
157
|
+
# "Ray executor: received termination signal - " "killing all actors",
|
|
158
|
+
# EngineEventData.interrupted(list(step_keys)),
|
|
159
|
+
# )
|
|
160
|
+
# stopping = True
|
|
161
|
+
# active_execution.mark_interrupted()
|
|
162
|
+
#
|
|
163
|
+
# # cancels all active actors
|
|
164
|
+
# def kill_actor(actor):
|
|
165
|
+
# try:
|
|
166
|
+
# ray.kill(actor)
|
|
167
|
+
# except ray.exceptions.RayActorError:
|
|
168
|
+
# # actor already dead
|
|
169
|
+
# pass
|
|
170
|
+
#
|
|
171
|
+
# list(map(kill_actor, active_actors))
|
|
172
|
+
#
|
|
173
|
+
# # start iterators
|
|
174
|
+
# while len(active_iters) < limit and not stopping:
|
|
175
|
+
# steps = active_execution.get_steps_to_execute(limit=(limit - len(active_iters)))
|
|
176
|
+
#
|
|
177
|
+
# if not steps:
|
|
178
|
+
# break
|
|
179
|
+
#
|
|
180
|
+
# for step in steps:
|
|
181
|
+
# step_context = plan_context.for_step(step)
|
|
182
|
+
# # need max_concurrency otherwise get will block when
|
|
183
|
+
# # when trying to fetch any events
|
|
184
|
+
# # thread concurrency is considered experimental
|
|
185
|
+
# # consider async
|
|
186
|
+
#
|
|
187
|
+
# actor = RayProcessCommand.options(
|
|
188
|
+
# max_concurrency=2,
|
|
189
|
+
# # num_cpus=step_context.tags
|
|
190
|
+
# **self._resources,
|
|
191
|
+
# ).remote(
|
|
192
|
+
# run_config=step_context.run_config,
|
|
193
|
+
# pipeline_run=step_context.pipeline_run,
|
|
194
|
+
# instance_ref=step_context.instance.get_ref(),
|
|
195
|
+
# step_key=step.key,
|
|
196
|
+
# recon_pipeline=pipeline,
|
|
197
|
+
# retry_mode=self.retries,
|
|
198
|
+
# known_state=active_execution.get_known_state(),
|
|
199
|
+
# )
|
|
200
|
+
# # term_events[step.key] = multiproc_ctx.Event()
|
|
201
|
+
# active_iters[step.key] = execute_step_out_of_process(actor, step_context)
|
|
202
|
+
# actors[step.key] = actor
|
|
203
|
+
#
|
|
204
|
+
# # process active iterators
|
|
205
|
+
# empty_iters = []
|
|
206
|
+
# for key, step_iter in active_iters.items():
|
|
207
|
+
# try:
|
|
208
|
+
# event_or_none = next(step_iter)
|
|
209
|
+
# if event_or_none is None:
|
|
210
|
+
# continue
|
|
211
|
+
# else:
|
|
212
|
+
# yield event_or_none
|
|
213
|
+
# active_execution.handle_event(event_or_none)
|
|
214
|
+
#
|
|
215
|
+
# # except ChildProcessCrashException as crash:
|
|
216
|
+
# # serializable_error = serializable_error_info_from_exc_info(
|
|
217
|
+
# # sys.exc_info()
|
|
218
|
+
# # )
|
|
219
|
+
# # step_context = plan_context.for_step(
|
|
220
|
+
# # active_execution.get_step_by_key(key)
|
|
221
|
+
# # )
|
|
222
|
+
# # yield DagsterEvent.engine_event(
|
|
223
|
+
# # step_context,
|
|
224
|
+
# # (
|
|
225
|
+
# # "Multiprocess executor: child process for step {step_key} "
|
|
226
|
+
# # "unexpectedly exited with code {exit_code}"
|
|
227
|
+
# # ).format(step_key=key, exit_code=crash.exit_code),
|
|
228
|
+
# # EngineEventData.engine_error(serializable_error),
|
|
229
|
+
# # )
|
|
230
|
+
# # step_failure_event = DagsterEvent.step_failure_event(
|
|
231
|
+
# # step_context=plan_context.for_step(
|
|
232
|
+
# # active_execution.get_step_by_key(key)
|
|
233
|
+
# # ),
|
|
234
|
+
# # step_failure_data=StepFailureData(
|
|
235
|
+
# # error=serializable_error, user_failure_data=None
|
|
236
|
+
# # ),
|
|
237
|
+
# # )
|
|
238
|
+
# # active_execution.handle_event(step_failure_event)
|
|
239
|
+
# # yield step_failure_event
|
|
240
|
+
# # empty_iters.append(key)
|
|
241
|
+
# except StopIteration:
|
|
242
|
+
# # raise Exception()
|
|
243
|
+
# empty_iters.append(key)
|
|
244
|
+
# # clear and mark complete finished iterators
|
|
245
|
+
# # plan_context.log.info(list(actors.keys()))
|
|
246
|
+
# for key in empty_iters:
|
|
247
|
+
# del active_iters[key]
|
|
248
|
+
# del actors[key]
|
|
249
|
+
# active_execution.verify_complete(plan_context, key)
|
|
250
|
+
#
|
|
251
|
+
# # process skipped and abandoned steps
|
|
252
|
+
# yield from active_execution.plan_events_iterator(plan_context)
|
|
253
|
+
#
|
|
254
|
+
# # TODO: handle errors properly
|
|
255
|
+
# errs = {actor: None for step_key, actor in active_iters.items() if not actor.heartbeat()}
|
|
256
|
+
#
|
|
257
|
+
# # After termination starts, raise an interrupted exception once all subprocesses
|
|
258
|
+
# # have finished cleaning up (and the only errors were from being interrupted)
|
|
259
|
+
# if (
|
|
260
|
+
# stopping
|
|
261
|
+
# and (not active_iters)
|
|
262
|
+
# and all([err_info.cls_name == "DagsterExecutionInterruptedError" for err_info in errs.values()])
|
|
263
|
+
# ):
|
|
264
|
+
# yield DagsterEvent.engine_event(
|
|
265
|
+
# plan_context,
|
|
266
|
+
# "Ray executor: killed all active child processes",
|
|
267
|
+
# event_specific_data=EngineEventData(),
|
|
268
|
+
# )
|
|
269
|
+
# raise DagsterExecutionInterruptedError()
|
|
270
|
+
# elif errs:
|
|
271
|
+
# raise DagsterSubprocessError(
|
|
272
|
+
# "During ray execution errors occurred in actors:\n{error_list}".format(
|
|
273
|
+
# error_list="\n".join(
|
|
274
|
+
# [
|
|
275
|
+
# "In process {pid}: {err}".format(pid=pid, err=err.to_string())
|
|
276
|
+
# for pid, err in errs.items()
|
|
277
|
+
# ]
|
|
278
|
+
# )
|
|
279
|
+
# ),
|
|
280
|
+
# subprocess_error_infos=list(errs.values()),
|
|
281
|
+
# )
|
|
282
|
+
#
|
|
283
|
+
# yield DagsterEvent.engine_event(
|
|
284
|
+
# plan_context,
|
|
285
|
+
# "Ray executor: driver exiting after {duration}".format(
|
|
286
|
+
# duration=format_duration(timer_result.millis),
|
|
287
|
+
# ),
|
|
288
|
+
# event_specific_data=EngineEventData.multiprocess(os.getpid()),
|
|
289
|
+
# )
|
|
290
|
+
#
|
|
291
|
+
#
|
|
292
|
+
# def wait_fetch(obj):
|
|
293
|
+
# complete, _ = ray.wait([obj], timeout=0, fetch_local=True)
|
|
294
|
+
#
|
|
295
|
+
# if complete:
|
|
296
|
+
# return ray.get(obj, timeout=RAY_TIMEOUT)
|
|
297
|
+
#
|
|
298
|
+
# return False
|
|
299
|
+
#
|
|
300
|
+
#
|
|
301
|
+
# def execute_step_out_of_process(actor, step_context):
|
|
302
|
+
# # engine_event
|
|
303
|
+
# # yield DagsterEvent.step_worker_starting(
|
|
304
|
+
# # step_context,
|
|
305
|
+
# # 'Launching ray actor for "{}".'.format(step.key),
|
|
306
|
+
# # metadata_entries=[],
|
|
307
|
+
# # )
|
|
308
|
+
# # raise Exception(command.__dir__())
|
|
309
|
+
# finished = actor.start.remote()
|
|
310
|
+
# next_ref = actor.next.remote()
|
|
311
|
+
# # ray.get(finished)
|
|
312
|
+
# while True:
|
|
313
|
+
# # check finished before getting any events
|
|
314
|
+
# # is_finished = wait_fetch(finished)
|
|
315
|
+
#
|
|
316
|
+
# # will block here, not ideal
|
|
317
|
+
# # this required in case is_finished is but the next return is in flight
|
|
318
|
+
# ret = wait_fetch(next_ref)
|
|
319
|
+
#
|
|
320
|
+
# # step_context.log.info(f"{ret}, {is_finished}")
|
|
321
|
+
#
|
|
322
|
+
# if ret == (1, 1, 1):
|
|
323
|
+
# # with capture_interrupts():
|
|
324
|
+
# try:
|
|
325
|
+
# # will except if the call did
|
|
326
|
+
# _ = ray.get(finished, timeout=RAY_TIMEOUT)
|
|
327
|
+
# except (
|
|
328
|
+
# Exception,
|
|
329
|
+
# KeyboardInterrupt,
|
|
330
|
+
# DagsterExecutionInterruptedError,
|
|
331
|
+
# ):
|
|
332
|
+
# yield DagsterEvent.engine_event(
|
|
333
|
+
# step_context,
|
|
334
|
+
# message="interrupted",
|
|
335
|
+
# event_specific_data=EngineEventData(),
|
|
336
|
+
# )
|
|
337
|
+
# return
|
|
338
|
+
# if ret is None or isinstance(ret, DagsterEvent):
|
|
339
|
+
# next_ref = actor.next.remote()
|
|
340
|
+
# yield ret
|
|
341
|
+
# elif not ret:
|
|
342
|
+
# # ret is false (wait_fetch not ready)
|
|
343
|
+
# yield None
|
|
344
|
+
# else:
|
|
345
|
+
# check.failed("Unexpected return value from actor {}".format(type(ret)))
|
|
346
|
+
# # continue
|
|
347
|
+
# # try:
|
|
348
|
+
# # # throws exception when actor is dead
|
|
349
|
+
# # ray.get(actor.heartbeat.remote(), timeout=RAY_TIMEOUT)
|
|
350
|
+
# # except ray.exceptions.RayActorError:
|
|
351
|
+
# # return
|
|
352
|
+
# # except ray.exceptions.GetTimeoutError:
|
|
353
|
+
# # yield DagsterEvent.engine_event(
|
|
354
|
+
# # step_context,
|
|
355
|
+
# # message=f"get timed out",
|
|
356
|
+
# # event_specific_data=EngineEventData(),
|
|
357
|
+
# # )
|
|
358
|
+
# # raise
|
|
359
|
+
#
|
|
360
|
+
#
|
|
361
|
+
# @executor(
|
|
362
|
+
# name="ray",
|
|
363
|
+
# config_schema=
|
|
364
|
+
# )
|
|
365
|
+
# def ray_executor(init_context: InitExecutorContext):
|
|
366
|
+
# """Ray-based executor."""
|
|
367
|
+
# cwd = Path(os.getcwd())
|
|
368
|
+
#
|
|
369
|
+
# exc_cfg = init_context.executor_config
|
|
370
|
+
# ray_host = exc_cfg.get("host", "localhost")
|
|
371
|
+
# ray_port = exc_cfg.get("port", 10001)
|
|
372
|
+
# code_dir = exc_cfg.get("code_dir", cwd.as_posix())
|
|
373
|
+
# requirements_path = exc_cfg.get("requirements_path")
|
|
374
|
+
# max_concurrency = exc_cfg.get("max_concurrency", 10)
|
|
375
|
+
#
|
|
376
|
+
# reqs = []
|
|
377
|
+
# if requirements_path is not None:
|
|
378
|
+
# reqs = Path(requirements_path).read_text().split("\n")
|
|
379
|
+
#
|
|
380
|
+
# ray.init(
|
|
381
|
+
# f"ray://{ray_host}:{ray_port}", runtime_env={"working_dir": code_dir, "pip": reqs},
|
|
382
|
+
# storage=exc_cfg.get("storage")
|
|
383
|
+
# )
|
|
384
|
+
# return RayExecutor(retries=RetryMode.DISABLED, max_concurrent=max_concurrency)
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
# import os
|
|
2
|
+
# from pathlib import Path
|
|
3
|
+
# from typing import Iterator, List, Optional, cast, Dict, Any, Sequence
|
|
4
|
+
#
|
|
5
|
+
# import kubernetes.config
|
|
6
|
+
# import ray
|
|
7
|
+
# from dagster import (
|
|
8
|
+
# Field,
|
|
9
|
+
# IntSource,
|
|
10
|
+
# Noneable,
|
|
11
|
+
# StringSource,
|
|
12
|
+
# _check as check,
|
|
13
|
+
# executor, DagsterInstance, JobExecutionResult,
|
|
14
|
+
# )
|
|
15
|
+
# from dagster._core.definitions import ReconstructableJob
|
|
16
|
+
# from dagster._core.definitions.executor_definition import multiple_process_executor_requirements
|
|
17
|
+
# from dagster._core.definitions.metadata import MetadataValue
|
|
18
|
+
# from dagster._core.events import DagsterEvent, EngineEventData
|
|
19
|
+
# from dagster._core.execution.api import execute_plan_iterator, create_execution_plan, execute_plan, execute_job, \
|
|
20
|
+
# ReexecutionOptions
|
|
21
|
+
# from dagster._core.execution.plan.state import KnownExecutionState
|
|
22
|
+
# from dagster._core.execution.retries import RetryMode, get_retries_config
|
|
23
|
+
# from dagster._core.execution.tags import get_tag_concurrency_limits_config
|
|
24
|
+
# from dagster._core.executor.base import Executor
|
|
25
|
+
# from dagster._core.executor.init import InitExecutorContext
|
|
26
|
+
# from dagster._core.executor.step_delegating import (
|
|
27
|
+
# CheckStepHealthResult,
|
|
28
|
+
# StepDelegatingExecutor,
|
|
29
|
+
# StepHandler,
|
|
30
|
+
# StepHandlerContext,
|
|
31
|
+
# )
|
|
32
|
+
# from ray import ObjectRef
|
|
33
|
+
# from ray.actor import ActorHandle
|
|
34
|
+
# from dagster._utils.merger import merge_dicts
|
|
35
|
+
#
|
|
36
|
+
# USER_DEFINED_RAY_CONFIG_SCHEMA = {}
|
|
37
|
+
#
|
|
38
|
+
# RAY_TIMEOUT = 5.
|
|
39
|
+
#
|
|
40
|
+
# RAY_EXECUTOR_CONFIG_SCHEMA = {
|
|
41
|
+
# "host": Field(str, is_required=False, description="Ray Cluster host"),
|
|
42
|
+
# "port": Field(int, is_required=False, description="Ray Cluster port"),
|
|
43
|
+
# "code_dir": Field(str, is_required=False),
|
|
44
|
+
# "requirements_path": Field(str, is_required=False),
|
|
45
|
+
# "image": Field(str, default_value=os.getenv("DAGSTER_CURRENT_IMAGE"), is_required=False),
|
|
46
|
+
# "max_concurrency": Field(int, is_required=False),
|
|
47
|
+
# "storage": Field(Noneable(str), is_required=False, description="Shared storage path for Ray workers"),
|
|
48
|
+
# "resources": Field(Noneable(Dict[str, Any]),
|
|
49
|
+
# is_required=False, description="Resources to pass to Ray workers"),
|
|
50
|
+
# "retries": get_retries_config(),
|
|
51
|
+
# "max_concurrent": Field(
|
|
52
|
+
# IntSource,
|
|
53
|
+
# is_required=False,
|
|
54
|
+
# description=(
|
|
55
|
+
# "Limit on the number of pods that will run concurrently within the scope "
|
|
56
|
+
# "of a Dagster run. Note that this limit is per run, not global."
|
|
57
|
+
# ),
|
|
58
|
+
# ),
|
|
59
|
+
# "tag_concurrency_limits": get_tag_concurrency_limits_config(),
|
|
60
|
+
# "step_k8s_config": Field(
|
|
61
|
+
# dict,
|
|
62
|
+
# is_required=False,
|
|
63
|
+
# description="Raw Ray configuration for each step launched by the executor.",
|
|
64
|
+
# )
|
|
65
|
+
# }
|
|
66
|
+
#
|
|
67
|
+
#
|
|
68
|
+
#
|
|
69
|
+
#
|
|
70
|
+
# class RayStepHandler(StepHandler):
|
|
71
|
+
# @property
|
|
72
|
+
# def name(self):
|
|
73
|
+
# return "RayStepHandler"
|
|
74
|
+
#
|
|
75
|
+
# def __init__(
|
|
76
|
+
# self,
|
|
77
|
+
# host: str,
|
|
78
|
+
# port: int = 6379,
|
|
79
|
+
# image: Optional[str] = None,
|
|
80
|
+
# code_dir: Optional[str] = None,
|
|
81
|
+
# requirements_path: Optional[str] = None,
|
|
82
|
+
# storage: Optional[str] = None,
|
|
83
|
+
# resources: Optional[Dict[str, Any]] = None,
|
|
84
|
+
# ):
|
|
85
|
+
# super().__init__()
|
|
86
|
+
#
|
|
87
|
+
# self._image = check.str_param(image, "image")
|
|
88
|
+
# self._host = check.opt_str_param(host, "host", default="localhost")
|
|
89
|
+
# self._port = check.int_param(port, "port")
|
|
90
|
+
# self._code_dir = check.opt_str_param(code_dir, "code_dir")
|
|
91
|
+
# self._requirements_path = check.opt_str_param(requirements_path, "requirements_path")
|
|
92
|
+
# self._storage = check.opt_str_param(storage, "storage")
|
|
93
|
+
# self._resources = check.opt_dict_param(resources, "resources")
|
|
94
|
+
#
|
|
95
|
+
# runtime_env = {}
|
|
96
|
+
#
|
|
97
|
+
# if self._code_dir is not None:
|
|
98
|
+
# runtime_env["working_dir"] = self._code_dir
|
|
99
|
+
#
|
|
100
|
+
# if self._requirements_path is not None:
|
|
101
|
+
# reqs = Path(self._requirements_path).read_text().split("\n")
|
|
102
|
+
# runtime_env["pip"] = reqs
|
|
103
|
+
#
|
|
104
|
+
# if self._image is not None:
|
|
105
|
+
# runtime_env["container"] = {
|
|
106
|
+
# "image": self._image,
|
|
107
|
+
# }
|
|
108
|
+
#
|
|
109
|
+
# ray.init(
|
|
110
|
+
# address=f"ray://{host}:{port}",
|
|
111
|
+
# runtime_env=runtime_env,
|
|
112
|
+
# storage=self._storage,
|
|
113
|
+
# )
|
|
114
|
+
#
|
|
115
|
+
# self.steps_refs: Dict[str, ObjectRef] = {}
|
|
116
|
+
#
|
|
117
|
+
# def _get_step_key(self, step_handler_context: StepHandlerContext) -> str:
|
|
118
|
+
#
|
|
119
|
+
# step_keys_to_execute = cast(
|
|
120
|
+
# List[str], step_handler_context.execute_step_args.step_keys_to_execute
|
|
121
|
+
# )
|
|
122
|
+
# assert len(step_keys_to_execute) == 1, "Launching multiple steps is not currently supported"
|
|
123
|
+
# return step_keys_to_execute[0]
|
|
124
|
+
#
|
|
125
|
+
# @ray.remote
|
|
126
|
+
# def execute_on_ray(self, step_handler_context: StepHandlerContext) -> JobExecutionResult:
|
|
127
|
+
# step_key = self._get_step_key(step_handler_context)
|
|
128
|
+
# instance = step_handler_context.instance
|
|
129
|
+
# dagster_run = step_handler_context.dagster_run
|
|
130
|
+
# run_config = step_handler_context.dagster_run.run_config
|
|
131
|
+
#
|
|
132
|
+
# return execute_job(
|
|
133
|
+
# job=step_handler_context._plan_context.reconstructable_job, # noqa
|
|
134
|
+
# instance=instance,
|
|
135
|
+
# run_config=run_config,
|
|
136
|
+
# op_selection=step_handler_context.dagster_run.resolved_op_selection,
|
|
137
|
+
# reexecution_options=ReexecutionOptions(
|
|
138
|
+
# parent_run_id=dagster_run.get_parent_run_id(),
|
|
139
|
+
# step_selection=[step_key]
|
|
140
|
+
# ),
|
|
141
|
+
# tags=dagster_run.tags,
|
|
142
|
+
# )
|
|
143
|
+
#
|
|
144
|
+
# def launch_step(self, step_handler_context: StepHandlerContext) -> Iterator[DagsterEvent]:
|
|
145
|
+
# step_key = self._get_step_key(step_handler_context)
|
|
146
|
+
# run = step_handler_context.dagster_run
|
|
147
|
+
# labels = {
|
|
148
|
+
# "dagster/job": run.job_name,
|
|
149
|
+
# "dagster/op": step_key,
|
|
150
|
+
# "dagster/run-id": step_handler_context.execute_step_args.run_id,
|
|
151
|
+
# }
|
|
152
|
+
# if run.external_job_origin:
|
|
153
|
+
# labels["dagster/code-location"] = (
|
|
154
|
+
# run.external_job_origin.external_repository_origin.code_location_origin.location_name
|
|
155
|
+
# )
|
|
156
|
+
#
|
|
157
|
+
# yield DagsterEvent.step_worker_starting(
|
|
158
|
+
# step_handler_context.get_step_context(step_key),
|
|
159
|
+
# message=f'Executing step "{step_key}" in Ray Cluster',
|
|
160
|
+
# metadata={
|
|
161
|
+
# "uri": MetadataValue.path(f"ray://{self._host}:{self._port}"),
|
|
162
|
+
# },
|
|
163
|
+
# )
|
|
164
|
+
#
|
|
165
|
+
# self.steps_refs[step_key] = self.execute_on_ray.options(num_cpus=..., num_gpus=...)
|
|
166
|
+
# .remote(step_handler_context)
|
|
167
|
+
#
|
|
168
|
+
# def check_step_health(self, step_handler_context: StepHandlerContext) -> CheckStepHealthResult:
|
|
169
|
+
# step_key = self._get_step_key(step_handler_context)
|
|
170
|
+
#
|
|
171
|
+
# complete, _ = ray.wait([self.steps_refs[step_key]], timeout=0, fetch_local=False)
|
|
172
|
+
#
|
|
173
|
+
# if status.failed:
|
|
174
|
+
# return CheckStepHealthResult.unhealthy(
|
|
175
|
+
# reason=f"Discovered failed Kubernetes job {job_name} for step {step_key}.",
|
|
176
|
+
# )
|
|
177
|
+
#
|
|
178
|
+
# return CheckStepHealthResult.healthy()
|
|
179
|
+
#
|
|
180
|
+
# def terminate_step(self, step_handler_context: StepHandlerContext) -> Iterator[DagsterEvent]:
|
|
181
|
+
# step_key = self._get_step_key(step_handler_context)
|
|
182
|
+
#
|
|
183
|
+
# job_name = self._get_k8s_step_job_name(step_handler_context)
|
|
184
|
+
# container_context = self._get_container_context(step_handler_context)
|
|
185
|
+
#
|
|
186
|
+
# yield DagsterEvent.engine_event(
|
|
187
|
+
# step_handler_context.get_step_context(step_key),
|
|
188
|
+
# message=f"Deleting Kubernetes job {job_name} for step",
|
|
189
|
+
# event_specific_data=EngineEventData(),
|
|
190
|
+
# )
|
|
191
|
+
#
|
|
192
|
+
# self._api_client.delete_job(job_name=job_name, namespace=container_context.namespace)
|
|
193
|
+
#
|
|
194
|
+
# def _wait_fetch(self, ref: ObjectRef) -> Optional[Any]:
|
|
195
|
+
# complete, _ = ray.wait([ref], timeout=0, fetch_local=True)
|
|
196
|
+
#
|
|
197
|
+
# if complete:
|
|
198
|
+
# return ray.get(ref, timeout=RAY_TIMEOUT)
|
|
199
|
+
# else:
|
|
200
|
+
# return None
|
|
201
|
+
#
|
|
202
|
+
# def _execute_in_ray(self, actor: ActorHandle, step_handler_context: StepHandlerContext):
|
|
203
|
+
# finished = actor.start.remote()
|
|
204
|
+
# next_ref = actor.next.remote()
|
|
205
|
+
# while True:
|
|
206
|
+
# # check finished before getting any events
|
|
207
|
+
# # is_finished = wait_fetch(finished)
|
|
208
|
+
#
|
|
209
|
+
# # will block here, not ideal
|
|
210
|
+
# # this required in case is_finished is but the next return is in flight
|
|
211
|
+
# ret = self._wait_fetch(next_ref)
|
|
212
|
+
#
|
|
213
|
+
# if ret == (1, 1, 1):
|
|
214
|
+
# # with capture_interrupts():
|
|
215
|
+
# try:
|
|
216
|
+
# # will except if the call did
|
|
217
|
+
# _ = ray.get(finished, timeout=RAY_TIMEOUT)
|
|
218
|
+
# except (
|
|
219
|
+
# Exception,
|
|
220
|
+
# KeyboardInterrupt,
|
|
221
|
+
# DagsterExecutionInterruptedError,
|
|
222
|
+
# ):
|
|
223
|
+
# yield DagsterEvent.engine_event(
|
|
224
|
+
# step_context,
|
|
225
|
+
# message="interrupted",
|
|
226
|
+
# event_specific_data=EngineEventData(),
|
|
227
|
+
# )
|
|
228
|
+
# return
|
|
229
|
+
# if ret is None or isinstance(ret, DagsterEvent):
|
|
230
|
+
# next_ref = actor.next.remote()
|
|
231
|
+
# yield ret
|
|
232
|
+
# elif not ret:
|
|
233
|
+
# # ret is false (wait_fetch not ready)
|
|
234
|
+
# yield None
|
|
235
|
+
# else:
|
|
236
|
+
# check.failed("Unexpected return value from actor {}".format(type(ret)))
|
|
237
|
+
# # continue
|
|
238
|
+
# # try:
|
|
239
|
+
# # # throws exception when actor is dead
|
|
240
|
+
# # ray.get(actor.heartbeat.remote(), timeout=RAY_TIMEOUT)
|
|
241
|
+
# # except ray.exceptions.RayActorError:
|
|
242
|
+
# # return
|
|
243
|
+
# # except ray.exceptions.GetTimeoutError:
|
|
244
|
+
# # yield DagsterEvent.engine_event(
|
|
245
|
+
# # step_context,
|
|
246
|
+
# # message=f"get timed out",
|
|
247
|
+
# # event_specific_data=EngineEventData(),
|
|
248
|
+
# # )
|
|
249
|
+
# # raise
|
|
250
|
+
#
|
|
251
|
+
#
|
|
252
|
+
# @executor(
|
|
253
|
+
# name="ray",
|
|
254
|
+
# config_schema=RAY_EXECUTOR_CONFIG_SCHEMA,
|
|
255
|
+
# requirements=multiple_process_executor_requirements(),
|
|
256
|
+
# )
|
|
257
|
+
# def ray_executor(init_context: InitExecutorContext) -> Executor:
|
|
258
|
+
# """Executor which launches steps with Ray
|
|
259
|
+
#
|
|
260
|
+
# `max_concurrent` limits the number of steps that will execute concurrently for one run. By default
|
|
261
|
+
# there is no limit- it will maximally parallel as allowed by the DAG. Note that this is not a
|
|
262
|
+
# global limit.
|
|
263
|
+
#
|
|
264
|
+
# Configuration set using `tags` on a `@job` will only apply to the `run` level. For configuration
|
|
265
|
+
# to apply at each `step` it must be set using `tags` for each `@op`.
|
|
266
|
+
# """
|
|
267
|
+
# # run_launcher = (
|
|
268
|
+
# # init_context.instance.run_launcher
|
|
269
|
+
# # if isinstance(init_context.instance.run_launcher, K8sRunLauncher)
|
|
270
|
+
# # else None
|
|
271
|
+
# # )
|
|
272
|
+
#
|
|
273
|
+
# exc_cfg = init_context.executor_config
|
|
274
|
+
#
|
|
275
|
+
# return StepDelegatingExecutor(
|
|
276
|
+
# RayStepHandler(
|
|
277
|
+
# ...
|
|
278
|
+
# ),
|
|
279
|
+
# retries=RetryMode.from_config(exc_cfg["retries"]), # type: ignore
|
|
280
|
+
# max_concurrent=check.opt_int_elem(exc_cfg, "max_concurrent"),
|
|
281
|
+
# tag_concurrency_limits=check.opt_list_elem(exc_cfg, "tag_concurrency_limits"),
|
|
282
|
+
# should_verify_step=True,
|
|
283
|
+
# )
|
|
284
|
+
#
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# import pickle
|
|
2
|
+
# from typing import Any
|
|
3
|
+
#
|
|
4
|
+
# import ray
|
|
5
|
+
#
|
|
6
|
+
# from dagster import UPathIOManager, InputContext, OutputContext, InitResourceContext, ConfigurableIOManager
|
|
7
|
+
# from pydantic import PrivateAttr
|
|
8
|
+
# from upath import UPath
|
|
9
|
+
#
|
|
10
|
+
# from dagster_ray.resource import RayResource
|
|
11
|
+
#
|
|
12
|
+
#
|
|
13
|
+
# class BaseRayIOManager(ConfigurableIOManager, UPathIOManager):
|
|
14
|
+
# base_dir: str
|
|
15
|
+
# extension: str = ".ray"
|
|
16
|
+
# ray: RayResource
|
|
17
|
+
#
|
|
18
|
+
# _base_path: UPath = PrivateAttr()
|
|
19
|
+
#
|
|
20
|
+
# def setup_for_execution(self, context: InitResourceContext) -> None:
|
|
21
|
+
# self._base_path = UPath(self.base_dir)
|
|
22
|
+
#
|
|
23
|
+
# def dump_to_path(self, context: OutputContext, obj: Any, path: "UPath"):
|
|
24
|
+
# ref = ray.put(obj)
|
|
25
|
+
# path.write_bytes(pickle.dumps(ref))
|
|
26
|
+
#
|
|
27
|
+
#
|
|
28
|
+
# class RayRefIOManager(BaseRayIOManager):
|
|
29
|
+
# def load_from_path(self, context: InputContext, path: "UPath") -> ray.ObjectRef:
|
|
30
|
+
# ref = pickle.loads(path.read_bytes())
|
|
31
|
+
# assert isinstance(ref, ray.ObjectRef)
|
|
32
|
+
# return ref
|
|
33
|
+
#
|
|
34
|
+
# #
|
|
35
|
+
# # class RayIOManager(BaseRayIOManager):
|
|
36
|
+
# # def load_from_path(self, context: InputContext, path: "UPath") -> Any:
|
|
37
|
+
# # ref = pickle.loads(path.read_bytes())
|
|
38
|
+
# # return ray.get(ref)
|
|
File without changes
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from contextlib import contextmanager
|
|
4
|
+
from typing import Generator, Optional
|
|
5
|
+
|
|
6
|
+
import ray
|
|
7
|
+
from dagster import ConfigurableResource, InitResourceContext
|
|
8
|
+
|
|
9
|
+
from dagster_ray.configs import RuntimeEnvConfig
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class RayResource(ConfigurableResource):
|
|
13
|
+
"""
|
|
14
|
+
A resource that provides access to the Ray cluster.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
address: Optional[str]
|
|
18
|
+
local: bool = False
|
|
19
|
+
runtime_env: Optional[RuntimeEnvConfig] = None
|
|
20
|
+
storage: Optional[str] = None
|
|
21
|
+
# todo: add requirements_path
|
|
22
|
+
|
|
23
|
+
@contextmanager
|
|
24
|
+
def yield_for_execution(self, context: InitResourceContext) -> Generator[RayResource, None, None]:
|
|
25
|
+
"""
|
|
26
|
+
Setups Ray and yields the resource.
|
|
27
|
+
Warning: this will shutdown the Ray process after execution.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
# raise RuntimeError()
|
|
31
|
+
assert context.log is not None
|
|
32
|
+
|
|
33
|
+
if self.runtime_env is not None:
|
|
34
|
+
runtime_env = self.runtime_env.dict()
|
|
35
|
+
else:
|
|
36
|
+
runtime_env = {}
|
|
37
|
+
|
|
38
|
+
if runtime_env.get("container") is not None and runtime_env["container"].get("image") is None:
|
|
39
|
+
assert context.dagster_run is not None
|
|
40
|
+
runtime_env["container"]["image"] = context.dagster_run.tags.get("dagster/image")
|
|
41
|
+
|
|
42
|
+
ray.init(
|
|
43
|
+
self.address,
|
|
44
|
+
runtime_env=runtime_env,
|
|
45
|
+
storage=self.storage,
|
|
46
|
+
)
|
|
47
|
+
if self.address is not None:
|
|
48
|
+
context.log.info(f"Connected to Ray Cluster at {self.address}")
|
|
49
|
+
|
|
50
|
+
yield self
|
|
51
|
+
|
|
52
|
+
ray.shutdown()
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
RAY_RESOURCE_CONFIG_SCHEMA = RayResource.to_fields_dict()
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "dagster-ray"
|
|
3
|
+
version = "0.0.0"
|
|
4
|
+
description = "Dagster integration library for Ray"
|
|
5
|
+
authors = [
|
|
6
|
+
"Daniel Gafni <danielgafni16@gmail.com>"
|
|
7
|
+
]
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
packages = [{include = "dagster_ray"}]
|
|
10
|
+
repository = "https://github.com/danielgafni/dagster-ray"
|
|
11
|
+
keywords = [
|
|
12
|
+
"dagster",
|
|
13
|
+
"ray",
|
|
14
|
+
"ETL",
|
|
15
|
+
"distributed",
|
|
16
|
+
]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Programming Language :: Python :: 3.8",
|
|
19
|
+
"Programming Language :: Python :: 3.9",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"License :: OSI Approved :: Apache Software License",
|
|
23
|
+
"Operating System :: OS Independent",
|
|
24
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
25
|
+
]
|
|
26
|
+
license = "Apache-2.0"
|
|
27
|
+
|
|
28
|
+
[tool.poetry.dependencies]
|
|
29
|
+
python = "^3.8"
|
|
30
|
+
dagster = "^1.3.5"
|
|
31
|
+
pyarrow = ">=8.0.0"
|
|
32
|
+
ray = "^2.6.3"
|
|
33
|
+
dagster-k8s = "^0.20.10"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
[tool.poetry.group.dev.dependencies]
|
|
37
|
+
hypothesis = "^6.77.0"
|
|
38
|
+
pytest = "^7.3.1"
|
|
39
|
+
deepdiff = "^6.3.0"
|
|
40
|
+
isort = "^5.12.0"
|
|
41
|
+
ruff = "^0.0.272"
|
|
42
|
+
pyright = "^1.1.313"
|
|
43
|
+
tox = "^4.6.0"
|
|
44
|
+
tox-gh = "^1.0.0"
|
|
45
|
+
pre-commit = "^3.3.2"
|
|
46
|
+
dagit = "^1.3.9"
|
|
47
|
+
black = "^23.3.0"
|
|
48
|
+
pytest-cases = "^3.6.14"
|
|
49
|
+
|
|
50
|
+
[build-system]
|
|
51
|
+
requires = ["poetry-core"]
|
|
52
|
+
build-backend = "poetry.core.masonry.api"
|
|
53
|
+
|
|
54
|
+
[tool.poetry-dynamic-versioning]
|
|
55
|
+
enable = true
|
|
56
|
+
strict = false
|
|
57
|
+
vcs = "git"
|
|
58
|
+
style = "pep440"
|
|
59
|
+
dirty = true
|
|
60
|
+
|
|
61
|
+
[tool.poetry-dynamic-versioning.substitution]
|
|
62
|
+
files = [
|
|
63
|
+
"pyproject.toml",
|
|
64
|
+
"dagster_ray/_version.py"
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
[tool.pytest.ini_options]
|
|
68
|
+
log_cli = true
|
|
69
|
+
log_level = "INFO"
|
|
70
|
+
|
|
71
|
+
[tool.isort]
|
|
72
|
+
profile = "black"
|
|
73
|
+
line_length = 120
|
|
74
|
+
src_paths = ["dagster_ray", "tests"]
|
|
75
|
+
|
|
76
|
+
[tool.black]
|
|
77
|
+
line-length = 120
|
|
78
|
+
target-version = ['py39']
|
|
79
|
+
include = '\.pyi?$'
|
|
80
|
+
exclude = '''
|
|
81
|
+
/(
|
|
82
|
+
\.eggs
|
|
83
|
+
| \.git
|
|
84
|
+
| \.hg
|
|
85
|
+
| \.mypy_cache
|
|
86
|
+
| \.pytest_cache
|
|
87
|
+
| \.ruff_cache
|
|
88
|
+
| \.venv
|
|
89
|
+
| build
|
|
90
|
+
| dist
|
|
91
|
+
)/
|
|
92
|
+
'''
|
|
93
|
+
|
|
94
|
+
[tool.ruff]
|
|
95
|
+
line-length = 120
|
|
96
|
+
src = [
|
|
97
|
+
"dagster_ray",
|
|
98
|
+
"tests"
|
|
99
|
+
]
|
|
100
|
+
exclude = [
|
|
101
|
+
".bzr",
|
|
102
|
+
".direnv",
|
|
103
|
+
".eggs",
|
|
104
|
+
".git",
|
|
105
|
+
".hg",
|
|
106
|
+
".mypy_cache",
|
|
107
|
+
".nox",
|
|
108
|
+
".pants.d",
|
|
109
|
+
".ruff_cache",
|
|
110
|
+
".svn",
|
|
111
|
+
".tox",
|
|
112
|
+
".venv",
|
|
113
|
+
"__pypackages__",
|
|
114
|
+
"_build",
|
|
115
|
+
"buck-out",
|
|
116
|
+
"build",
|
|
117
|
+
"dist",
|
|
118
|
+
"node_modules",
|
|
119
|
+
"venv",
|
|
120
|
+
]
|
|
121
|
+
[tool.ruff.isort]
|
|
122
|
+
known-first-party = ["dagster_ray", "tests"]
|
|
123
|
+
|
|
124
|
+
[tool.pyright]
|
|
125
|
+
reportPropertyTypeMismatch = true
|
|
126
|
+
reportImportCycles = true
|
|
127
|
+
reportWildcardImportFromLibrary = true
|
|
128
|
+
reportUntypedFunctionDecorator = true
|
|
129
|
+
reportUntypedClassDecorator = true
|
|
130
|
+
|
|
131
|
+
include = [
|
|
132
|
+
"dagster_ray",
|
|
133
|
+
"tests"
|
|
134
|
+
]
|
|
135
|
+
exclude = [
|
|
136
|
+
".bzr",
|
|
137
|
+
".direnv",
|
|
138
|
+
".eggs",
|
|
139
|
+
".git",
|
|
140
|
+
".hg",
|
|
141
|
+
".mypy_cache",
|
|
142
|
+
".nox",
|
|
143
|
+
".pants.d",
|
|
144
|
+
".ruff_cache",
|
|
145
|
+
".svn",
|
|
146
|
+
".tox",
|
|
147
|
+
".venv",
|
|
148
|
+
"__pypackages__",
|
|
149
|
+
"_build",
|
|
150
|
+
"buck-out",
|
|
151
|
+
"build",
|
|
152
|
+
"dist",
|
|
153
|
+
"node_modules",
|
|
154
|
+
"venv",
|
|
155
|
+
]
|