Cron workflow
CronWorkflow
CronWorkflow allows a user to run a Workflow on a recurring basis.
Note
Hera’s CronWorkflow is a subclass of Workflow which means certain fields are renamed
for compatibility, see cron_suspend and cron_status which are different from the Argo
spec. See CronWorkflowSpec for more details.
Source code in src/hera/workflows/cron_workflow.py
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 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
pod_priority
DEPRECATED: The spec.podPriority field was removed in 3.7, so does not map to anything. Use pod_priority_class_name instead.
workflows_service
workflows_service: Optional[
Union[WorkflowsService, AsyncWorkflowsService]
] = None
Container
The Container defines a container to run on Argo.
A container generally consists of running a Docker container remotely, which is configured via fields such as
image, command and args.
See how to use it in the Container example.
Source code in src/hera/workflows/container.py
get_artifact
Finds and returns the artifact with the supplied name.
Note that this method will raise an error if the artifact is not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of the input artifact to find and return. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Artifact |
Artifact
|
the artifact with the supplied name. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if the artifact is not found. |
Source code in src/hera/workflows/_mixins.py
get_parameter
Finds and returns the parameter with the supplied name.
Note that this method will raise an error if the parameter is not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of the input parameter to find and return. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Parameter |
Parameter
|
the parameter with the supplied name. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if the parameter is not found. |
Source code in src/hera/workflows/_mixins.py
DAG
A DAG template invocator is used to define Task dependencies as an acyclic graph.
DAG implements the contextmanager interface so allows usage of with, under which any Task
objects instantiated will be added to the DAG’s list of Tasks.
See the DAG examples for usage.
Source code in src/hera/workflows/dag.py
get_artifact
Finds and returns the artifact with the supplied name.
Note that this method will raise an error if the artifact is not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of the input artifact to find and return. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Artifact |
Artifact
|
the artifact with the supplied name. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if the artifact is not found. |
Source code in src/hera/workflows/_mixins.py
get_parameter
Finds and returns the parameter with the supplied name.
Note that this method will raise an error if the parameter is not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of the input parameter to find and return. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Parameter |
Parameter
|
the parameter with the supplied name. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if the parameter is not found. |
Source code in src/hera/workflows/_mixins.py
Data
Data implements the Argo data template representation.
Data can be used to indicate that some data, identified by a source, should be processed via the specified
transformations. The transformations field can be either expressed via a pure str or via a hera.expr,
which transpiles the expression into a statement that can be processed by Argo.
Source code in src/hera/workflows/data.py
get_artifact
Finds and returns the artifact with the supplied name.
Note that this method will raise an error if the artifact is not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of the input artifact to find and return. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Artifact |
Artifact
|
the artifact with the supplied name. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if the artifact is not found. |
Source code in src/hera/workflows/_mixins.py
get_parameter
Finds and returns the parameter with the supplied name.
Note that this method will raise an error if the parameter is not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of the input parameter to find and return. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Parameter |
Parameter
|
the parameter with the supplied name. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if the parameter is not found. |
Source code in src/hera/workflows/_mixins.py
HTTP
HTTP is an implementation of the HTTP template that supports executing HTTP actions in a step/task.
Source code in src/hera/workflows/http_template.py
get_artifact
Finds and returns the artifact with the supplied name.
Note that this method will raise an error if the artifact is not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of the input artifact to find and return. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Artifact |
Artifact
|
the artifact with the supplied name. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if the artifact is not found. |
Source code in src/hera/workflows/_mixins.py
get_parameter
Finds and returns the parameter with the supplied name.
Note that this method will raise an error if the parameter is not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of the input parameter to find and return. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Parameter |
Parameter
|
the parameter with the supplied name. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if the parameter is not found. |
Source code in src/hera/workflows/_mixins.py
ModelMapper
Source code in src/hera/workflows/_meta_mixins.py
build_model
build_model(
hera_class: Type[ModelMapperMixin],
hera_obj: ModelMapperMixin,
model: TWorkflow,
) -> TWorkflow
Source code in src/hera/workflows/_meta_mixins.py
Resource
Resource is a representation of a K8s resource that can be created by Argo.
The resource is a callable step that can be invoked in a DAG/Workflow. The resource can create any K8s resource,
such as other workflows, workflow templates, daemons, etc, as specified by the manifest field of the resource.
The manifest field is a canonical YAML that is submitted to K8s by Argo. Note that the manifest is a union of
multiple types. The manifest can be a string, in which case it is assume to be YAML. Otherwise, if it’s a Hera
objects, it is automatically converted to the corresponding YAML representation.
Source code in src/hera/workflows/resource.py
get_artifact
Finds and returns the artifact with the supplied name.
Note that this method will raise an error if the artifact is not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of the input artifact to find and return. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Artifact |
Artifact
|
the artifact with the supplied name. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if the artifact is not found. |
Source code in src/hera/workflows/_mixins.py
get_parameter
Finds and returns the parameter with the supplied name.
Note that this method will raise an error if the parameter is not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of the input parameter to find and return. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Parameter |
Parameter
|
the parameter with the supplied name. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if the parameter is not found. |
Source code in src/hera/workflows/_mixins.py
Script
A Script in Argo Workflows acts as a wrapper around a Container, where you can specify Python code to run through source.
In Hera, you should aim to use the script decorator, rather than the Script class directly. You will need to refer to the Script class for the kwargs that the decorator can take, but your IDE should give you code completion and type hints.
Source code in src/hera/workflows/script.py
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 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 354 | |
get_artifact
Finds and returns the artifact with the supplied name.
Note that this method will raise an error if the artifact is not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of the input artifact to find and return. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Artifact |
Artifact
|
the artifact with the supplied name. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if the artifact is not found. |
Source code in src/hera/workflows/_mixins.py
get_parameter
Finds and returns the parameter with the supplied name.
Note that this method will raise an error if the parameter is not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of the input parameter to find and return. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Parameter |
Parameter
|
the parameter with the supplied name. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if the parameter is not found. |
Source code in src/hera/workflows/_mixins.py
Steps
A Steps template invocator is used to define a sequence of steps which can run sequentially or in parallel.
Steps implements the contextmanager interface so allows usage of with, under which any
hera.workflows.steps.Step objects instantiated will be added to the Steps’ list of sub_steps.
- Step and Parallel objects initialised within a Steps context will be added to the list of sub_steps in the order they are initialised.
- All Step objects initialised within a Parallel context will run in parallel.
Source code in src/hera/workflows/steps.py
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 | |
sub_steps
sub_steps: List[
Union[
Step,
Parallel,
List[Step],
WorkflowStep,
List[WorkflowStep],
]
] = []
get_artifact
Finds and returns the artifact with the supplied name.
Note that this method will raise an error if the artifact is not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of the input artifact to find and return. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Artifact |
Artifact
|
the artifact with the supplied name. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if the artifact is not found. |
Source code in src/hera/workflows/_mixins.py
get_parameter
Finds and returns the parameter with the supplied name.
Note that this method will raise an error if the parameter is not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of the input parameter to find and return. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Parameter |
Parameter
|
the parameter with the supplied name. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if the parameter is not found. |
Source code in src/hera/workflows/_mixins.py
Suspend
The Suspend template allows the user to pause a workflow for a specified length of time.
The workflow can pause based on the given by duration or indefinitely (i.e. until manually resumed).
The Suspend template also allows you to specify intermediate_parameters which will replicate the given
parameters to the “inputs” and “outputs” of the template, resulting in a Suspend template that pauses and
waits for values from the user for the given list of parameters.
Source code in src/hera/workflows/suspend.py
get_artifact
Finds and returns the artifact with the supplied name.
Note that this method will raise an error if the artifact is not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of the input artifact to find and return. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Artifact |
Artifact
|
the artifact with the supplied name. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if the artifact is not found. |
Source code in src/hera/workflows/_mixins.py
get_parameter
Finds and returns the parameter with the supplied name.
Note that this method will raise an error if the parameter is not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of the input parameter to find and return. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Parameter |
Parameter
|
the parameter with the supplied name. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if the parameter is not found. |
Source code in src/hera/workflows/_mixins.py
add_template_set
Add the templates stored in the template_set to this Workflow.
async_create
Creates the CronWorkflow on the Argo cluster.
Source code in src/hera/workflows/cron_workflow.py
async_get
Attempts to get a cron workflow based on the parameters of this template e.g. name + namespace.
Source code in src/hera/workflows/cron_workflow.py
async_lint
Lints the CronWorkflow using the Argo cluster.
Source code in src/hera/workflows/cron_workflow.py
async_update
Attempts to perform a workflow template update based on the parameters of this template.
Note that this creates the template if it does not exist. In addition, this performs
a get prior to updating to get the resource version to update in the first place. If you know the template
does not exist ahead of time, it is more efficient to use create() directly to avoid one round trip.
Source code in src/hera/workflows/cron_workflow.py
async_wait
async_wait(poll_interval: int = 5) -> TWorkflow
Waits for the Workflow to complete execution.
Parameters
poll_interval: int = 5 The interval in seconds to poll the workflow status.
Source code in src/hera/workflows/workflow.py
build
Builds the CronWorkflow and its components into an Argo schema CronWorkflow object.
Source code in src/hera/workflows/cron_workflow.py
container
container(**container_kwargs) -> Callable
container_template
container_template(**container_kwargs) -> Callable
Source code in src/hera/workflows/_meta_mixins.py
create
Creates the CronWorkflow on the Argo cluster.
Source code in src/hera/workflows/cron_workflow.py
dag
dag(**dag_kwargs) -> Callable
data_template
data_template(**container_kwargs) -> Callable
from_dict
from_dict(model_dict: Dict) -> ModelMapperMixin
Create a CronWorkflow from a CronWorkflow contained in a dict.
Examples:
>>> my_cron_workflow = CronWorkflow(name="my-cron-wf")
>>> my_cron_workflow == CronWorkflow.from_dict(my_cron_workflow.to_dict())
True
Source code in src/hera/workflows/cron_workflow.py
from_file
Create a CronWorkflow from a CronWorkflow contained in a YAML file.
Examples:
Source code in src/hera/workflows/cron_workflow.py
from_yaml
from_yaml(yaml_str: str) -> ModelMapperMixin
Create a CronWorkflow from a CronWorkflow contained in a YAML string.
Examples:
Source code in src/hera/workflows/cron_workflow.py
get
Attempts to get a cron workflow based on the parameters of this template e.g. name + namespace.
Source code in src/hera/workflows/cron_workflow.py
get_parameter
Attempts to find and return a Parameter of the specified name.
Source code in src/hera/workflows/workflow.py
get_workflow_link
get_workflow_link() -> str
Returns the workflow link for the workflow.
Source code in src/hera/workflows/cron_workflow.py
http_template
http_template(**container_kwargs) -> Callable
lint
Lints the CronWorkflow using the Argo cluster.
Source code in src/hera/workflows/cron_workflow.py
resource_template
resource_template(**container_kwargs) -> Callable
Source code in src/hera/workflows/_meta_mixins.py
script
script(**script_kwargs) -> Callable
A decorator that wraps a function into a Script object.
Using this decorator users can define a function that will be executed as a script in a container. Once the
Script is returned users can use it as they generally use a Script e.g. as a callable inside a DAG or Steps.
Note that invoking the function will result in the template associated with the script to be added to the
workflow context, so users do not have to worry about that.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**script_kwargs
|
Keyword arguments to be passed to the Script object. |
{}
|
Returns:
| Type | Description |
|---|---|
Callable
|
Function wrapper that holds a |
Source code in src/hera/workflows/_meta_mixins.py
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 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 | |
set_entrypoint
Decorator function to set entrypoint.
Source code in src/hera/workflows/workflow.py
steps
steps(**steps_kwargs) -> Callable
suspend_template
suspend_template(**container_kwargs) -> Callable
Source code in src/hera/workflows/_meta_mixins.py
to_dict
to_dict() -> Any
Builds the Workflow as an Argo schema Workflow object and returns it as a dictionary.
to_file
Writes the Workflow as an Argo schema Workflow object to a YAML file and returns the path to the file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_directory
|
Union[Path, str]
|
The directory to write the file to. Defaults to the current working directory. |
'.'
|
name
|
str
|
The name of the file to write without the file extension. Defaults to the Workflow’s name or a generated name. |
''
|
*args
|
Additional arguments to pass to |
()
|
|
**kwargs
|
Additional keyword arguments to pass to |
{}
|
Source code in src/hera/workflows/workflow.py
to_yaml
to_yaml(*args, **kwargs) -> str
Builds the Workflow as an Argo schema Workflow object and returns it as yaml string.
Source code in src/hera/workflows/workflow.py
update
Attempts to perform a workflow template update based on the parameters of this template.
Note that this creates the template if it does not exist. In addition, this performs
a get prior to updating to get the resource version to update in the first place. If you know the template
does not exist ahead of time, it is more efficient to use create() directly to avoid one round trip.
Source code in src/hera/workflows/cron_workflow.py
wait
wait(poll_interval: int = 5) -> TWorkflow
Waits for the Workflow to complete execution.
Parameters
poll_interval: int = 5 The interval in seconds to poll the workflow status.