API Reference
This page is automatically generated from the source code docstrings.
Manages and executes a collection of interdependent tasks.
A Process orchestrates the execution of multiple tasks, handling dependency resolution, task ordering. Task execution can be performed in parallel or sequentially. It provides logging management and error propagation for dependent tasks. If a task fails, all tasks depending on it are marked as failed without execution, but non-dependent tasks continue to run.
Attributes
tasks : list[Task] List of tasks to be executed, automatically sorted by dependencies. runner : ProcessRunner The runner responsible for executing the tasks.
Raises
TypeError If tasks is not a list or contains non-Task elements. ValueError If duplicate task names are found. DependencyNotFoundError If a task depends on a non-existent task. CircularDependencyError If circular dependencies are detected among tasks.
Source code in src/processes/process.py
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 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 | |
__enter__()
Called when entering the 'with' block.
Source code in src/processes/process.py
88 89 90 | |
__exit__(exc_type, exc_value, traceback)
Called when exiting the 'with' block, even if an error occurred.
Source code in src/processes/process.py
92 93 94 95 96 97 98 99 100 | |
close_loggers()
Close and clean up all logger handlers for all tasks.
Should be called when the process is done to ensure proper resource cleanup.
Source code in src/processes/process.py
262 263 264 265 266 267 268 269 270 | |
get_dependant_tasks(task_name)
Retrieve all tasks that directly or indirectly depend on a given task.
Parameters
task_name : str The name of the task to find dependants for.
Returns
list[Task] List of all tasks that depend on the specified task, including transitive dependencies (tasks that depend on tasks that depend on the specified task).
Source code in src/processes/process.py
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 | |
get_task(task_name)
Retrieve a task by name.
Parameters
task_name : str The name of the task to retrieve.
Returns
Task The task with the specified name.
Raises
TaskNotFoundError If no task with the given name exists.
Source code in src/processes/process.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
run(parallel=None, max_workers=4)
Execute all tasks in the process.
Runs tasks sequentially or in parallel while respecting dependencies. Dependencies are always resolved before dependent tasks are executed.
Parameters
parallel : bool, optional Whether to run tasks in parallel while respecting dependencies. If None, automatically set to True for processes with 10 or more tasks, False otherwise. Defaults to None. max_workers : int, optional Maximum number of worker threads for parallel execution. Defaults to 4. Only used when parallel=True. If set to 1, falls back to sequential execution.
Returns
ProcessResult Contains passed_tasks_results (dict mapping task names to TaskResult) and failed_tasks (set of task names that failed).
Source code in src/processes/process.py
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 | |
Container for the results of a process execution.
Holds the outcomes of all tasks executed in a process, separating successful and failed tasks with their respective results.
Attributes
passed_tasks_results : dict[str, TaskResult] Mapping of task names to TaskResult objects for all tasks that executed successfully. failed_tasks : set[str] Set of task names for all tasks that failed during execution.
Source code in src/processes/process.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
A Task represents a unit of work to be executed within a Process.
A Task encapsulates a callable function with its arguments, dependencies on other tasks, and logging configuration. Tasks can be executed, by the Process class, sequentially or in parallel, with automatic dependency resolution and result passing between dependent tasks.
Attributes
name : str Unique name for the task (cannot contain spaces). log_path : str File path where task logs will be written. func : Callable The function to execute when the task runs. args : tuple Positional arguments to pass to the function. Defaults to empty tuple. kwargs : dict Keyword arguments to pass to the function. Defaults to empty dict. dependencies : list[TaskDependency] List of tasks this task depends on. Defaults to empty list. html_mail_handler : HTMLSMTPHandler, optional Handler for sending error logs via email in HTML format. Defaults to None. logger : logging.Logger Logger instance for this task, automatically configured.
Source code in src/processes/task.py
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 291 292 293 294 295 296 297 298 299 300 301 302 | |
get_dependencies_names()
Get the names of all tasks this task depends on.
Returns
set[str] Set of dependency task names.
Source code in src/processes/task.py
235 236 237 238 239 240 241 242 243 244 | |
run(executing_process=None)
Execute the task's function with its arguments and dependencies.
This method runs the task's function, automatically injecting results from dependent tasks as specified in the dependency configuration. Logs the task execution and captures any exceptions.
Parameters
executing_process : Process, optional The parent Process executing this task. Used to retrieve results from dependent tasks. Defaults to None.
Returns
TaskResult Object containing: - worked (bool): True if execution succeeded, False otherwise. - result: The return value of the function if successful, None if failed. - exception (Exception | None): The exception raised if execution failed, None if successful.
Source code in src/processes/task.py
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 | |
Represents a dependency relationship between tasks.
Defines how a task depends on another task, including how the result of the dependency should be passed to the dependent task (as additional positional arguments, keyword arguments, or both).
Attributes
task_name : str The name of the task this dependency refers to. use_result_as_additional_args : bool If True, the result of the dependency task will be passed as an additional positional argument as the last argument. Defaults to False. use_result_as_additional_kwargs : bool If True, the result of the dependency task will be passed as a keyword argument. Defaults to False. additional_kwarg_name : str | None The name of the keyword argument to use if use_result_as_additional_kwargs is True. Required when use_result_as_additional_kwargs is True. Defaults to None.
Raises
TypeError If any parameter type is invalid or if use_result_as_additional_kwargs is True but additional_kwarg_name is not a string.
Source code in src/processes/task.py
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 | |
__hash__()
Return hash of the dependency based on task name.
Returns
int Hash value based on the task_name attribute.
Source code in src/processes/task.py
98 99 100 101 102 103 104 105 106 107 | |
Bases: SMTPHandler
A logging handler that sends log records via SMTP as HTML formatted emails.
Extends the standard SMTPHandler to support HTML-formatted email messages, enabling richer formatting and styling in error notifications.
Attributes
mailhost : tuple[str, int] A tuple of (host, port) for the SMTP server. fromaddr : str The email address to send messages from. toaddrs : list[str] List of email addresses to send messages to. credentials : tuple[str, str] | None A tuple of (username, password) for SMTP authentication. Defaults to None. secure : tuple | tuple[str, str] | tuple[str, str, ssl.SSLContext] | None Security configuration for SMTP connection. Can be an empty tuple for no security, a tuple of (certfile, keyfile), or (certfile, keyfile, SSLContext). Defaults to None. timeout : int Connection timeout in seconds. Defaults to 5.
Source code in src/processes/html_logging.py
10 11 12 13 14 15 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 | |
__copy__()
Support for copy.copy() method.
Returns
HTMLSMTPHandler A shallow copy of this handler.
Source code in src/processes/html_logging.py
79 80 81 82 83 84 85 86 87 | |
copy()
Create a shallow copy of this handler.
Returns
HTMLSMTPHandler A new HTMLSMTPHandler instance with the same configuration.
Source code in src/processes/html_logging.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
emit(record)
Send a log record via email as HTML formatted message.
Formats the log record using the handler's formatter and sends it as an HTML-formatted email. Errors during sending are handled gracefully.
Parameters
record : logging.LogRecord The log record to send.
Source code in src/processes/html_logging.py
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 | |