prefect.utilities.engine
collect_task_run_inputs(expr, max_depth=-1)
async
This function recurses through an expression to generate a set of any discernible task run inputs it finds in the data structure. It produces a set of all inputs found.
Examples:
>>> task_inputs = {
>>> k: await collect_task_run_inputs(v) for k, v in parameters.items()
>>> }
Source code in src/prefect/utilities/engine.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
collect_task_run_inputs_sync(expr, future_cls=PrefectFuture, max_depth=-1)
This function recurses through an expression to generate a set of any discernible task run inputs it finds in the data structure. It produces a set of all inputs found.
Examples:
>>> task_inputs = {
>>> k: collect_task_run_inputs_sync(v) for k, v in parameters.items()
>>> }
Source code in src/prefect/utilities/engine.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
get_state_for_result(obj)
Get the state related to a result object.
link_state_to_result
must have been called first.
Source code in src/prefect/utilities/engine.py
584 585 586 587 588 589 590 591 592 |
|
link_state_to_result(state, result)
Caches a link between a state and a result and its components using
the id
of the components to map to the state. The cache is persisted to the
current flow run context since task relationships are limited to within a flow run.
This allows dependency tracking to occur when results are passed around.
Note: Because id
is used, we cannot cache links between singleton objects.
We only cache the relationship between components 1-layer deep. Example: Given the result [1, ["a","b"], ("c",)], the following elements will be mapped to the state: - [1, ["a","b"], ("c",)] - ["a","b"] - ("c",)
Note: the int `1` will not be mapped to the state because it is a singleton.
Other Notes: We do not hash the result because: - If changes are made to the object in the flow between task calls, we can still track that they are related. - Hashing can be expensive. - Not all objects are hashable.
We do not set an attribute, e.g. __prefect_state__
, on the result because:
- Mutating user's objects is dangerous.
- Unrelated equality comparisons can break unexpectedly.
- The field can be preserved on copy.
- We cannot set this attribute on Python built-ins.
Source code in src/prefect/utilities/engine.py
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 |
|
propose_state(client, state, force=False, task_run_id=None, flow_run_id=None)
async
Propose a new state for a flow run or task run, invoking Prefect orchestration logic.
If the proposed state is accepted, the provided state
will be augmented with
details and returned.
If the proposed state is rejected, a new state returned by the Prefect API will be returned.
If the proposed state results in a WAIT instruction from the Prefect API, the function will sleep and attempt to propose the state again.
If the proposed state results in an ABORT instruction from the Prefect API, an error will be raised.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
State[object]
|
a new state for the task or flow run |
required |
task_run_id
|
Optional[UUID]
|
an optional task run id, used when proposing task run states |
None
|
flow_run_id
|
Optional[UUID]
|
an optional flow run id, used when proposing flow run states |
None
|
Returns:
Type | Description |
---|---|
State[object]
|
a State model representation of the flow or task run state |
Raises:
Type | Description |
---|---|
ValueError
|
if neither task_run_id or flow_run_id is provided |
Abort
|
if an ABORT instruction is received from the Prefect API |
Source code in src/prefect/utilities/engine.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
|
propose_state_sync(client, state, force=False, task_run_id=None, flow_run_id=None)
Propose a new state for a flow run or task run, invoking Prefect orchestration logic.
If the proposed state is accepted, the provided state
will be augmented with
details and returned.
If the proposed state is rejected, a new state returned by the Prefect API will be returned.
If the proposed state results in a WAIT instruction from the Prefect API, the function will sleep and attempt to propose the state again.
If the proposed state results in an ABORT instruction from the Prefect API, an error will be raised.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
State[object]
|
a new state for the task or flow run |
required |
task_run_id
|
Optional[UUID]
|
an optional task run id, used when proposing task run states |
None
|
flow_run_id
|
Optional[UUID]
|
an optional flow run id, used when proposing flow run states |
None
|
Returns:
Type | Description |
---|---|
State[object]
|
a State model representation of the flow or task run state |
Raises:
Type | Description |
---|---|
ValueError
|
if neither task_run_id or flow_run_id is provided |
Abort
|
if an ABORT instruction is received from the Prefect API |
Source code in src/prefect/utilities/engine.py
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 |
|
resolve_inputs(parameters, return_data=True, max_depth=-1)
async
Resolve any Quote
, PrefectFuture
, or State
types nested in parameters into
data.
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
A copy of the parameters with resolved data |
Raises:
Type | Description |
---|---|
UpstreamTaskError
|
If any of the upstream states are not |
Source code in src/prefect/utilities/engine.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
|
resolve_inputs_sync(parameters, return_data=True, max_depth=-1)
Resolve any Quote
, PrefectFuture
, or State
types nested in parameters into
data.
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
A copy of the parameters with resolved data |
Raises:
Type | Description |
---|---|
UpstreamTaskError
|
If any of the upstream states are not |
Source code in src/prefect/utilities/engine.py
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 |
|
resolve_to_final_result(expr, context)
Resolve any PrefectFuture
, or State
types nested in parameters into
data. Designed to be use with visit_collection
.
Source code in src/prefect/utilities/engine.py
833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 |
|