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

IWF-157: Fix typo IdReusePolicy of ALLOW_IF_PREVIOUS_EXISTS_ABNORMALLY #33

Merged
merged 15 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
12 changes: 6 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
with:
python-version: '3.9'
- name: Install deps
uses: knowsuchagency/poetry-install@v1
env:
POETRY_VIRTUALENVS_CREATE: false
uses: snok/install-poetry@v1
with:
virtualenvs-create: false
- name: Run linters
uses: pre-commit/[email protected]
pytest:
Expand All @@ -28,9 +28,9 @@ jobs:
with:
python-version: '3.9'
- name: Install deps
uses: knowsuchagency/poetry-install@v1
env:
POETRY_VIRTUALENVS_CREATE: false
uses: snok/install-poetry@v1
with:
virtualenvs-create: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied this value from somewhere else but didn't fully understand. do you know why this has to be 'false'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I don't know. I'm also not sure if calling 'poetry install' here will cause any downsides? It fixed the workflow issues.

- name: Run pytest check # sleep 30s to wait for the server to be ready
run: echo "[run]">>.coveragerc && echo "omit = iwf/iwf_api/">>.coveragerc && sleep 30 && poetry run pytest -vv --cov-config=.coveragerc --cov="iwf/" .
- name: Dump docker logs
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Python SDK for [iWF workflow engine](https://github.com/indeedeng/iwf)
pip install iwf-python-sdk==0.1.2
```

See [samples](https://github.com/indeedeng/iwf-python-samples) for use case examples.
See [samples](https://github.com/indeedeng/iwf-python-samples) for use case examples.

## Requirements

Expand Down Expand Up @@ -102,7 +102,7 @@ This project uses [openapi-python-client](https://github.com/openapi-generators/
cd iwf && poetry run openapi-python-client update --path ../iwf-idl/iwf-sdk.yaml --config .openapi-python-client-config.yaml
```

Then run `cd .. && cp -R iwf/iwf_api/iwf_api/* iwf/iwf_api && rm -R iwf/iwf_api/iwf_api && poetry update` to
Then run `cd .. && cp -R iwf/iwf_api/iwf_api/* iwf/iwf_api && rm -R iwf/iwf_api/iwf_api && poetry update` to
* Fix the api package path
* Update the local path dependency.
#### Linting
Expand Down
2 changes: 1 addition & 1 deletion iwf-idl
Submodule iwf-idl updated 3 files
+9 −1 README.md
+68 −13 iwf-sdk.yaml
+70 −12 iwf.yaml
5 changes: 3 additions & 2 deletions iwf/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ def start_workflow(
unreg_opts.workflow_id_reuse_policy = options.workflow_id_reuse_policy
unreg_opts.workflow_retry_policy = options.workflow_retry_policy
unreg_opts.cron_schedule = options.workflow_cron_schedule
unreg_opts.workflow_start_delay_seconds \
= options.workflow_start_delay_seconds
unreg_opts.workflow_start_delay_seconds = (
options.workflow_start_delay_seconds
)

# TODO: set initial search attributes here

Expand Down
2 changes: 1 addition & 1 deletion iwf/iwf_api/models/id_reuse_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class IDReusePolicy(str, Enum):
ALLOW_IF_NO_RUNNING = "ALLOW_IF_NO_RUNNING"
ALLOW_IF_PREVIOUS_EXISTS_ABNORMALLY = "ALLOW_IF_PREVIOUS_EXISTS_ABNORMALLY"
ALLOW_IF_PREVIOUS_EXITS_ABNORMALLY = "ALLOW_IF_PREVIOUS_EXITS_ABNORMALLY"
ALLOW_TERMINATE_IF_RUNNING = "ALLOW_TERMINATE_IF_RUNNING"
DISALLOW_REUSE = "DISALLOW_REUSE"

Expand Down
2 changes: 1 addition & 1 deletion iwf/py.typed
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# Marker file for PEP 561
# Marker file for PEP 561
65 changes: 65 additions & 0 deletions iwf/tests/test_abnormal_exit_workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import inspect
import time
import unittest
from typing import Union

from iwf.client import Client
from iwf.command_results import CommandResults
from iwf.communication import Communication
from iwf.errors import WorkflowFailed
from iwf.iwf_api.models import RetryPolicy
from iwf.iwf_api.models.id_reuse_policy import IDReusePolicy
from iwf.persistence import Persistence
from iwf.state_decision import StateDecision
from iwf.state_schema import StateSchema
from iwf.tests.test_basic_workflow import BasicWorkflow
from iwf.tests.worker_server import registry
from iwf.workflow import ObjectWorkflow
from iwf.workflow_context import WorkflowContext
from iwf.workflow_options import WorkflowOptions
from iwf.workflow_state import T, WorkflowState
from iwf.workflow_state_options import WorkflowStateOptions


class AbnormalExitState1(WorkflowState[Union[int, str]]):
def execute(
self,
ctx: WorkflowContext,
input: T,
command_results: CommandResults,
persistence: Persistence,
communication: Communication,
) -> StateDecision:
raise RuntimeError("abnormal exit state")

def get_state_options(self) -> WorkflowStateOptions:
return WorkflowStateOptions(
execute_api_retry_policy=RetryPolicy(maximum_attempts=1)
)


class AbnormalExitWorkflow(ObjectWorkflow):
def get_workflow_states(self) -> StateSchema:
return StateSchema.with_starting_state(AbnormalExitState1())


abnormal_exit_wf = AbnormalExitWorkflow()
registry.add_workflow(abnormal_exit_wf)
client = Client(registry)


class TestAbnormalWorkflow(unittest.TestCase):
def test_abnormal_exit_workflow(self):
wf_id = f"{inspect.currentframe().f_code.co_name}-{time.time_ns()}"
startOptions = WorkflowOptions(
workflow_id_reuse_policy=IDReusePolicy.ALLOW_IF_PREVIOUS_EXITS_ABNORMALLY
)

client.start_workflow(AbnormalExitWorkflow, wf_id, 100, "input", startOptions)
with self.assertRaises(WorkflowFailed):
client.get_simple_workflow_result_with_wait(wf_id, str)

# Starting a workflow with the same ID should be allowed since the previous failed abnormally
client.start_workflow(BasicWorkflow, wf_id, 100, "input", startOptions)
res = client.get_simple_workflow_result_with_wait(wf_id, str)
assert res == "done"
5 changes: 3 additions & 2 deletions iwf/unregistered_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ def start_workflow(
if options.cron_schedule:
start_options.cron_schedule = options.cron_schedule
if options.workflow_start_delay_seconds:
start_options.workflow_start_delay_seconds \
= options.workflow_start_delay_seconds
start_options.workflow_start_delay_seconds = (
options.workflow_start_delay_seconds
)
if options.workflow_retry_policy:
start_options.retry_policy = options.workflow_retry_policy

Expand Down
Loading
Loading