climate_ref_core.executor
#
Executor interface for running diagnostics
Executor
#
Bases: Protocol
An executor is responsible for running a diagnostic asynchronously
The diagnostic may be run locally in the same process or in a separate process or container.
Notes
This is an extremely basic interface and will be expanded in the future, as we figure out our requirements.
Source code in packages/climate-ref-core/src/climate_ref_core/executor.py
join(timeout)
#
Wait for all executions to finish
If the timeout is reached, the method will return and raise an exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float
|
Maximum time to wait for all executions to finish in seconds |
required |
Raises:
| Type | Description |
|---|---|
TimeoutError
|
If the timeout is reached |
Source code in packages/climate-ref-core/src/climate_ref_core/executor.py
run(definition, execution=None)
#
Execute a diagnostic with a given definition
No executions are returned from this method, as the execution may be performed asynchronously so executions may not be immediately available.
Note
In future, we may return a Future object that can be used to retrieve the result,
but that requires some additional work to implement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definition
|
ExecutionDefinition
|
Definition of the information needed to execute a diagnostic This definition describes which datasets are required to run the diagnostic and where the output should be stored. |
required |
execution
|
Execution | None
|
The execution object to update with the results of the execution. This is a database object that contains the executions of the execution. If provided, it will be updated with the executions of the execution. This may happen asynchronously, so the executions may not be immediately available. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
Results from running the diagnostic |
Source code in packages/climate-ref-core/src/climate_ref_core/executor.py
execute_locally(definition, log_level, raise_error=False)
#
Run a diagnostic execution
This is the chunk of work that should be executed by an executor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definition
|
ExecutionDefinition
|
A description of the information needed for this execution of the diagnostic |
required |
log_level
|
str
|
The log level to use for the execution |
required |
Source code in packages/climate-ref-core/src/climate_ref_core/executor.py
import_executor_cls(fqn)
#
Import an executor using a fully qualified module path
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fqn
|
str
|
Full package and attribute name of the executor to import For example: |
required |
Raises:
| Type | Description |
|---|---|
InvalidExecutorException
|
If the executor cannot be imported If the executor isn't a valid |
Returns:
| Type | Description |
|---|---|
type[Executor]
|
Executor instance |