yaml_workflow.tasks¶
yaml_workflow.tasks
¶
Task modules for the YAML Workflow Engine.
This package contains various task modules that can be used in workflows. Each module provides specific functionality that can be referenced in workflow YAML files.
Classes¶
TaskConfig
¶
Configuration class for task handlers with namespace support.
Source code in src/yaml_workflow/tasks/config.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 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 121 122 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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
Functions¶
get_available_variables() -> Dict[str, List[str]]
¶
Get available variables by namespace.
Returns:
Type | Description |
---|---|
Dict[str, List[str]]
|
Dict[str, List[str]]: Available variables in each namespace |
Source code in src/yaml_workflow/tasks/config.py
get_variable(name: str, namespace: Optional[str] = None) -> Any
¶
Get a variable with namespace support.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Variable name |
required |
namespace
|
Optional[str]
|
Optional namespace (args, env, steps) |
None
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
Variable value if found |
Source code in src/yaml_workflow/tasks/config.py
process_inputs() -> Dict[str, Any]
¶
Process task inputs with template resolution.
Recursively processes all string values in the inputs dictionary, including nested dictionaries and lists.
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: Processed inputs with resolved templates |
Source code in src/yaml_workflow/tasks/config.py
Functions¶
add_numbers(a: float, b: float) -> float
¶
Add two numbers together.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
float
|
First number |
required |
b
|
float
|
Second number |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
Sum of the numbers |
append_file_task(config: TaskConfig) -> Optional[Dict[str, Any]]
¶
Append content to a file.
Source code in src/yaml_workflow/tasks/file_tasks.py
batch_task(config: TaskConfig) -> Dict[str, Any]
¶
Process a batch of items using specified task configuration.
This task processes a list of items in parallel chunks using the specified task configuration. Each item is passed to the task as an argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
TaskConfig
|
TaskConfig object containing: - items: List of items to process - task: Task configuration for processing each item - arg_name: Name of the argument to use for each item (default: "item") - chunk_size: Optional size of chunks (default: 10) - max_workers: Optional maximum worker threads |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict containing: - processed: List of successfully processed items - failed: List of failed items with errors - results: List of processing results - stats: Processing statistics |
Example YAML usage
Source code in src/yaml_workflow/tasks/batch.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 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 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 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
|
create_greeting(name: str, context: Dict[str, Any]) -> str
¶
Create a greeting message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name to greet |
required |
context
|
Dict[str, Any]
|
Template context |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Greeting message |
Raises:
Type | Description |
---|---|
TemplateError
|
If template resolution fails |
Source code in src/yaml_workflow/tasks/basic_tasks.py
echo(message: str) -> str
¶
Echo back the input message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
str
|
Message to echo |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The input message |
fail(message: str = 'Task failed') -> None
¶
A task that always fails.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
str
|
Error message |
'Task failed'
|
Raises:
Type | Description |
---|---|
RuntimeError
|
Always raises this error |
get_task_handler(name: str) -> Optional[TaskHandler]
¶
Get a task handler by name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Task name |
required |
Returns:
Type | Description |
---|---|
Optional[TaskHandler]
|
Optional[TaskHandler]: Task handler if found |
Source code in src/yaml_workflow/tasks/__init__.py
hello_world(name: str = 'World') -> str
¶
A simple hello world function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name to include in greeting. Defaults to "World". |
'World'
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The greeting message |
Source code in src/yaml_workflow/tasks/basic_tasks.py
join_strings(*strings: str, separator: str = ' ') -> str
¶
Join multiple strings together.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*strings
|
str
|
Variable number of strings to join |
()
|
separator
|
str
|
String to use as separator. Defaults to space. |
' '
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Joined string |
Source code in src/yaml_workflow/tasks/basic_tasks.py
print_vars_task(config: TaskConfig) -> dict
¶
Prints selected variables from the context for debugging.
Source code in src/yaml_workflow/tasks/python_tasks.py
read_file_task(config: TaskConfig) -> Optional[Dict[str, Any]]
¶
Read content from a file.
Source code in src/yaml_workflow/tasks/file_tasks.py
read_json_task(config: TaskConfig) -> Optional[Dict[str, Any]]
¶
Task handler for reading JSON files.
Source code in src/yaml_workflow/tasks/file_tasks.py
read_yaml_task(config: TaskConfig) -> Optional[Dict[str, Any]]
¶
Task handler for reading YAML files.
Source code in src/yaml_workflow/tasks/file_tasks.py
register_task(name: Optional[str] = None) -> Callable[..., Callable[[TaskConfig], R]]
¶
Decorator to register a function as a workflow task.
Source code in src/yaml_workflow/tasks/__init__.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
|
render_template(config: TaskConfig) -> Dict[str, Any]
¶
Render a template and save it to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
TaskConfig
|
Task configuration object |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: Dictionary containing the path to the output file |
Raises:
Type | Description |
---|---|
TaskExecutionError
|
If template resolution fails or file cannot be written (via handle_task_error) |
Source code in src/yaml_workflow/tasks/template_tasks.py
shell_task(config: TaskConfig) -> Dict[str, Any]
¶
Run a shell command with namespace support.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
TaskConfig
|
Task configuration with namespace support |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: Command execution results |
Raises:
Type | Description |
---|---|
TaskExecutionError
|
If command execution fails or template resolution fails |
Source code in src/yaml_workflow/tasks/shell_tasks.py
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 268 269 270 271 |
|
write_file_task(config: TaskConfig) -> Optional[Dict[str, Any]]
¶
Write content to a file.
Source code in src/yaml_workflow/tasks/file_tasks.py
write_json_task(config: TaskConfig) -> Optional[Dict[str, Any]]
¶
Write JSON data to a file.
Source code in src/yaml_workflow/tasks/file_tasks.py
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 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 |
|
write_yaml_task(config: TaskConfig) -> Optional[Dict[str, Any]]
¶
Write YAML data to a file.