Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix validation error for retry strategy #558

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions docs/examples/workflows/upstream/retry_script.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Retry Script

> Note: This example is a replication of an Argo Workflow example in Hera. The upstream example can be [found here](https://github.com/argoproj/argo-workflows/blob/master/examples/retry-script.yaml).




=== "Hera"

```python linenums="1"
from hera.workflows import Workflow, script, RetryStrategy


@script(image="python:alpine3.6", retry_strategy=RetryStrategy(limit=10), add_cwd_to_sys_path=False)
def retry_script():
import random
import sys

exit_code = random.choice([0, 1, 1])
sys.exit(exit_code)


with Workflow(generate_name="retry-script-", entrypoint="retry-script") as w:
retry_script()
```

=== "YAML"

```yaml linenums="1"
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: retry-script-
spec:
entrypoint: retry-script
templates:
- name: retry-script
retryStrategy:
limit: '10'
script:
command:
- python
image: python:alpine3.6
source: 'import random

import sys


exit_code = random.choice([0, 1, 1])

sys.exit(exit_code)

'
```

20 changes: 20 additions & 0 deletions examples/workflows/upstream/retry-script.upstream.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This example demonstrates the use of retries for a single script.
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: retry-script-
spec:
entrypoint: retry-script
templates:
- name: retry-script
retryStrategy:
limit: "10"
script:
image: python:alpine3.6
command: ["python"]
# fail with a 66% probability
source: |
import random;
import sys;
exit_code = random.choice([0, 1, 1]);
sys.exit(exit_code)
24 changes: 24 additions & 0 deletions examples/workflows/upstream/retry-script.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: retry-script-
spec:
entrypoint: retry-script
templates:
- name: retry-script
retryStrategy:
limit: '10'
script:
command:
- python
image: python:alpine3.6
source: 'import random

import sys


exit_code = random.choice([0, 1, 1])

sys.exit(exit_code)

'
14 changes: 14 additions & 0 deletions examples/workflows/upstream/retry_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from hera.workflows import RetryStrategy, Workflow, script


@script(image="python:alpine3.6", retry_strategy=RetryStrategy(limit=10), add_cwd_to_sys_path=False)
def retry_script():
import random
import sys

exit_code = random.choice([0, 1, 1])
sys.exit(exit_code)


with Workflow(generate_name="retry-script-", entrypoint="retry-script") as w:
retry_script()
4 changes: 2 additions & 2 deletions src/hera/workflows/retry_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class RetryStrategy(_BaseModel):
affinity: Optional[RetryAffinity] = None
backoff: Optional[Backoff] = None
expression: Optional[str] = None
limit: Optional[Union[int, str]] = None
limit: Optional[Union[str, int, IntOrString]] = None
retry_policy: Optional[Union[str, RetryPolicy]] = None

@validator("retry_policy", pre=True)
Expand All @@ -52,7 +52,7 @@ def _convert_limit(cls, v):
if v is None or isinstance(v, IntOrString):
return v

return IntOrString(__root__=str(v)) # int or str
return str(v) # int or str

def build(self) -> _ModelRetryStrategy:
return _ModelRetryStrategy(
Expand Down