Tasks¶
tasks
¶
Defines daglite task decorator, task types, and metadata.
SyncTask
dataclass
¶
Bases: _BaseTask[P, R]
Eager task wrapping a synchronous function.
Calling an instance executes the function immediately and returns its result. When an execution context is active, events are emitted and hooks are fired.
Source code in src/daglite/tasks.py
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 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 | |
AsyncTask
dataclass
¶
Bases: _BaseTask[P, R]
Eager task wrapping an async coroutine function.
Calling an instance returns a coroutine that the caller must await. When an execution context
is active, events are emitted and hooks are fired.
Source code in src/daglite/tasks.py
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 | |
SyncTaskStream
dataclass
¶
Bases: _BaseTask[P, R]
Task wrapping a sync generator; yields items lazily.
Source code in src/daglite/tasks.py
AsyncTaskStream
dataclass
¶
Bases: _BaseTask[P, R]
Task wrapping an async generator; yields items lazily.
Source code in src/daglite/tasks.py
TaskMetadata
dataclass
¶
Lightweight metadata describing the currently executing task.
Source code in src/daglite/tasks.py
description
class-attribute
instance-attribute
¶
Optional description of the task.
inputs
class-attribute
instance-attribute
¶
Dictionary of input values passed to the task.
is_async
class-attribute
instance-attribute
¶
Whether the task is an async coroutine function.
is_generator
class-attribute
instance-attribute
¶
Whether the task is a generator function (sync or async).
map_index
class-attribute
instance-attribute
¶
Current map iteration index, if applicable.
parent_id
class-attribute
instance-attribute
¶
Unique identifier of the parent task, if any.
task
¶
task(
*,
name: str | None = None,
description: str | None = None,
backend: str | None = None,
retries: int = 0,
timeout: float | None = None,
cache: bool = False,
cache_store: CacheStore | str | None = None,
cache_ttl: int | None = None,
cache_hash: CacheHashFn | None = None,
dataset: str | None = None,
dataset_store: DatasetStore | str | None = None,
dataset_format: str | None = None,
) -> _TaskDecorator
task(
func: Any = None,
*,
name: str | None = None,
description: str | None = None,
backend: str | None = None,
retries: int = 0,
timeout: float | None = None,
cache: bool = False,
cache_store: CacheStore | str | None = None,
cache_ttl: int | None = None,
cache_hash: CacheHashFn | None = None,
dataset: str | None = None,
dataset_store: DatasetStore | str | None = None,
dataset_format: str | None = None,
) -> Any
Creates a daglite task from a sync or async function.
The decorated function executes immediately on call (no futures, no graph).
When called inside an active session or workflow it emits events, fires hooks, participates in caching, and can interact with dataset stores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Custom name of the task. Can include |
None
|
description
|
str | None
|
Description of the task. Defaults to the function's docstring if not provided. |
None
|
backend
|
str | None
|
Backend name for parallel operations. If |
None
|
retries
|
int
|
Number of automatic task retries on failure. |
0
|
timeout
|
float | None
|
Max execution time in seconds. |
None
|
cache
|
bool
|
Indicates whether the task participates in caching. Possible values include
* |
False
|
cache_ttl
|
int | None
|
Cache time-to-live (TTL) in seconds. This parameter ignored if cache is |
None
|
cache_hash
|
CacheHashFn | None
|
Custom |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
A sync or async eager task callable with the original signature. |
Source code in src/daglite/tasks.py
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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 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 | |