prefect-client 3.1.14__py3-none-any.whl → 3.1.15__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- prefect/__main__.py +4 -0
- prefect/_experimental/lineage.py +40 -22
- prefect/_internal/concurrency/services.py +1 -1
- prefect/_version.py +3 -3
- prefect/artifacts.py +408 -105
- prefect/blocks/core.py +1 -1
- prefect/blocks/notifications.py +5 -0
- prefect/client/schemas/actions.py +11 -1
- prefect/client/schemas/schedules.py +4 -4
- prefect/deployments/base.py +13 -16
- prefect/deployments/runner.py +117 -4
- prefect/events/clients.py +39 -0
- prefect/flow_engine.py +119 -0
- prefect/flows.py +252 -9
- prefect/runtime/task_run.py +37 -9
- prefect/tasks.py +8 -6
- prefect/utilities/render_swagger.py +1 -1
- prefect/utilities/templating.py +7 -0
- {prefect_client-3.1.14.dist-info → prefect_client-3.1.15.dist-info}/METADATA +1 -1
- {prefect_client-3.1.14.dist-info → prefect_client-3.1.15.dist-info}/RECORD +23 -22
- {prefect_client-3.1.14.dist-info → prefect_client-3.1.15.dist-info}/LICENSE +0 -0
- {prefect_client-3.1.14.dist-info → prefect_client-3.1.15.dist-info}/WHEEL +0 -0
- {prefect_client-3.1.14.dist-info → prefect_client-3.1.15.dist-info}/top_level.txt +0 -0
prefect/__main__.py
ADDED
prefect/_experimental/lineage.py
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
from typing import TYPE_CHECKING, Any, Dict, Literal, Optional, Sequence, Union
|
2
2
|
|
3
|
+
from typing_extensions import TypeAlias
|
4
|
+
|
3
5
|
from prefect.events.related import related_resources_from_run_context
|
4
|
-
from prefect.events.schemas.events import RelatedResource
|
6
|
+
from prefect.events.schemas.events import RelatedResource
|
5
7
|
from prefect.events.utilities import emit_event
|
6
8
|
from prefect.settings import get_current_settings
|
7
9
|
|
8
10
|
if TYPE_CHECKING:
|
9
11
|
from prefect.results import ResultStore
|
10
12
|
|
11
|
-
|
12
|
-
DownstreamResources = Sequence[Union[Resource, dict[str, str]]]
|
13
|
+
LineageResources: TypeAlias = Sequence[Union[RelatedResource, dict[str, str]]]
|
13
14
|
|
14
15
|
# Map block types to their URI schemes
|
15
16
|
STORAGE_URI_SCHEMES = {
|
@@ -47,8 +48,8 @@ def get_result_resource_uri(
|
|
47
48
|
|
48
49
|
async def emit_lineage_event(
|
49
50
|
event_name: str,
|
50
|
-
upstream_resources: Optional[
|
51
|
-
downstream_resources: Optional[
|
51
|
+
upstream_resources: Optional[LineageResources] = None,
|
52
|
+
downstream_resources: Optional[LineageResources] = None,
|
52
53
|
direction_of_run_from_event: Literal["upstream", "downstream"] = "downstream",
|
53
54
|
) -> None:
|
54
55
|
"""Emit lineage events showing relationships between resources.
|
@@ -73,7 +74,14 @@ async def emit_lineage_event(
|
|
73
74
|
downstream_resources = list(downstream_resources) if downstream_resources else []
|
74
75
|
|
75
76
|
async with get_client() as client:
|
76
|
-
|
77
|
+
context_resources = await related_resources_from_run_context(client)
|
78
|
+
|
79
|
+
tag_resources = [
|
80
|
+
res for res in context_resources if res.get("prefect.resource.role") == "tag"
|
81
|
+
]
|
82
|
+
context_resources = [
|
83
|
+
res for res in context_resources if res.get("prefect.resource.role") != "tag"
|
84
|
+
]
|
77
85
|
|
78
86
|
# NOTE: We handle adding run-related resources to the event here instead of in
|
79
87
|
# the EventsWorker because not all run-related resources are upstream from
|
@@ -82,9 +90,9 @@ async def emit_lineage_event(
|
|
82
90
|
# lineage-related events, tracks upstream resources only. For downstream
|
83
91
|
# resources, we need to emit an event for each downstream resource.
|
84
92
|
if direction_of_run_from_event == "downstream":
|
85
|
-
downstream_resources.extend(
|
93
|
+
downstream_resources.extend(context_resources)
|
86
94
|
else:
|
87
|
-
upstream_resources.extend(
|
95
|
+
upstream_resources.extend(context_resources)
|
88
96
|
|
89
97
|
# We want to consider all resources upstream and downstream of the event as
|
90
98
|
# lineage-related, including flows, flow runs, etc., so we add the label to
|
@@ -101,7 +109,7 @@ async def emit_lineage_event(
|
|
101
109
|
emit_kwargs: Dict[str, Any] = {
|
102
110
|
"event": event_name,
|
103
111
|
"resource": resource,
|
104
|
-
"related": upstream_resources,
|
112
|
+
"related": upstream_resources + tag_resources,
|
105
113
|
}
|
106
114
|
|
107
115
|
emit_event(**emit_kwargs)
|
@@ -110,7 +118,7 @@ async def emit_lineage_event(
|
|
110
118
|
async def emit_result_read_event(
|
111
119
|
store: "ResultStore",
|
112
120
|
result_key: str,
|
113
|
-
downstream_resources: Optional[
|
121
|
+
downstream_resources: Optional[LineageResources] = None,
|
114
122
|
cached: bool = False,
|
115
123
|
) -> None:
|
116
124
|
"""
|
@@ -150,7 +158,7 @@ async def emit_result_read_event(
|
|
150
158
|
async def emit_result_write_event(
|
151
159
|
store: "ResultStore",
|
152
160
|
result_key: str,
|
153
|
-
upstream_resources: Optional[
|
161
|
+
upstream_resources: Optional[LineageResources] = None,
|
154
162
|
) -> None:
|
155
163
|
"""
|
156
164
|
Emit a lineage event showing a task or flow result was written.
|
@@ -181,8 +189,10 @@ async def emit_result_write_event(
|
|
181
189
|
|
182
190
|
|
183
191
|
async def emit_external_resource_lineage(
|
184
|
-
|
185
|
-
|
192
|
+
event_name: str = "prefect.lineage.event",
|
193
|
+
upstream_resources: Optional[LineageResources] = None,
|
194
|
+
downstream_resources: Optional[LineageResources] = None,
|
195
|
+
context_resources: Optional[LineageResources] = None,
|
186
196
|
) -> None:
|
187
197
|
"""Emit lineage events connecting external resources to Prefect context resources.
|
188
198
|
|
@@ -206,11 +216,19 @@ async def emit_external_resource_lineage(
|
|
206
216
|
downstream_resources = list(downstream_resources) if downstream_resources else []
|
207
217
|
|
208
218
|
# Get the current Prefect context resources (flow runs, task runs, etc.)
|
209
|
-
|
210
|
-
|
219
|
+
if not context_resources:
|
220
|
+
async with get_client() as client:
|
221
|
+
context_resources = await related_resources_from_run_context(client)
|
222
|
+
|
223
|
+
tag_resources = [
|
224
|
+
res for res in context_resources if res.get("prefect.resource.role") == "tag"
|
225
|
+
]
|
226
|
+
context_resources = [
|
227
|
+
res for res in context_resources if res.get("prefect.resource.role") != "tag"
|
228
|
+
]
|
211
229
|
|
212
230
|
# Add lineage group label to all resources
|
213
|
-
for res in upstream_resources + downstream_resources:
|
231
|
+
for res in upstream_resources + downstream_resources + context_resources:
|
214
232
|
if "prefect.resource.lineage-group" not in res:
|
215
233
|
res["prefect.resource.lineage-group"] = "global"
|
216
234
|
|
@@ -218,26 +236,26 @@ async def emit_external_resource_lineage(
|
|
218
236
|
if upstream_resources:
|
219
237
|
for context_resource in context_resources:
|
220
238
|
emit_kwargs: Dict[str, Any] = {
|
221
|
-
"event": "prefect.
|
239
|
+
"event": "prefect.lineage.upstream-interaction",
|
222
240
|
"resource": context_resource,
|
223
|
-
"related": upstream_resources,
|
241
|
+
"related": upstream_resources + tag_resources,
|
224
242
|
}
|
225
243
|
emit_event(**emit_kwargs)
|
226
244
|
|
227
245
|
# For each downstream resource, emit an event showing it as downstream of context resources
|
228
246
|
for downstream_resource in downstream_resources:
|
229
247
|
emit_kwargs: Dict[str, Any] = {
|
230
|
-
"event": "prefect.
|
248
|
+
"event": "prefect.lineage.downstream-interaction",
|
231
249
|
"resource": downstream_resource,
|
232
|
-
"related": context_resources,
|
250
|
+
"related": context_resources + tag_resources,
|
233
251
|
}
|
234
252
|
emit_event(**emit_kwargs)
|
235
253
|
|
236
254
|
# For each downstream resource, emit an event showing it as downstream of upstream resources
|
237
255
|
if upstream_resources:
|
238
256
|
direct_emit_kwargs = {
|
239
|
-
"event":
|
257
|
+
"event": event_name,
|
240
258
|
"resource": downstream_resource,
|
241
|
-
"related": upstream_resources,
|
259
|
+
"related": upstream_resources + tag_resources,
|
242
260
|
}
|
243
261
|
emit_event(**direct_emit_kwargs)
|
@@ -65,7 +65,7 @@ class _QueueServiceBase(abc.ABC, Generic[T]):
|
|
65
65
|
# failure to process items. This is particularly relevant for services
|
66
66
|
# which use an httpx client. See related issue at
|
67
67
|
# https://github.com/python/cpython/issues/86813
|
68
|
-
threading._register_atexit(self._at_exit) # pyright: ignore[
|
68
|
+
threading._register_atexit(self._at_exit) # pyright: ignore[reportUnknownMemberType, reportAttributeAccessIssue]
|
69
69
|
|
70
70
|
def _at_exit(self) -> None:
|
71
71
|
self.drain(at_exit=True)
|
prefect/_version.py
CHANGED
@@ -8,11 +8,11 @@ import json
|
|
8
8
|
|
9
9
|
version_json = '''
|
10
10
|
{
|
11
|
-
"date": "2025-01-
|
11
|
+
"date": "2025-01-30T11:31:29-0800",
|
12
12
|
"dirty": true,
|
13
13
|
"error": null,
|
14
|
-
"full-revisionid": "
|
15
|
-
"version": "3.1.
|
14
|
+
"full-revisionid": "3ac3d54885a6157989efd79cbfc0d681b4bb7e0c",
|
15
|
+
"version": "3.1.15"
|
16
16
|
}
|
17
17
|
''' # END VERSION_JSON
|
18
18
|
|