Skip to content

Commit

Permalink
IWF-157: Fix typo IdReusePolicy of ALLOW_IF_PREVIOUS_EXISTS_ABNORMALLY (
Browse files Browse the repository at this point in the history
#33)

* IWF-157: Fix typo IdReusePolicy of ALLOW_IF_PREVIOUS_EXISTS_ABNORMALLY

* IWF-157: Fixing linter warnings

* IWF-157: Poetry install fix

* IWF-157: Poetry install fix

* IWF-157: Updating poetry.lock

* IWF-157: Adding ALLOW_IF_PREVIOUS_EXITS_ABNORMALLY unit test

* IWF-157: Fixing linter warning

* IWF-157: Fixing linter warning

* IWF-157: Attempting poetry deps fix

* IWF-157: Attempting poetry deps fix

* IWF-157: Poetry dep fix

* IWF-157: Poetry dep fix

* IWF-157: Poetry dep fix

* IWF-157: Poetry dep fix

* IWF-157: adding additional args to poetry install
  • Loading branch information
stevo89519 authored Oct 1, 2024
1 parent d9d41dc commit de39f87
Show file tree
Hide file tree
Showing 10 changed files with 436 additions and 328 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
uses: actions/setup-python@v3
with:
python-version: '3.9'
- name: Install deps
uses: knowsuchagency/poetry-install@v1
env:
POETRY_VIRTUALENVS_CREATE: false
- name: Install Poetry
uses: snok/install-poetry@v1
- name: Install Dependencies
run: poetry install --no-interaction --no-root
- name: Run linters
uses: pre-commit/[email protected]
pytest:
Expand All @@ -27,10 +27,10 @@ jobs:
uses: actions/setup-python@v3
with:
python-version: '3.9'
- name: Install deps
uses: knowsuchagency/poetry-install@v1
env:
POETRY_VIRTUALENVS_CREATE: false
- name: Install Poetry
uses: snok/install-poetry@v1
- name: Install Dependencies
run: poetry install --no-interaction --no-root
- 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/object_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def default(self, o: Any) -> Any:
See :py:meth:`json.JSONEncoder.default`.
"""
# Dataclass support
if dataclasses.is_dataclass(o):
if dataclasses.is_dataclass(o) and not isinstance(o, type):
return dataclasses.asdict(o)
# Support for models with "dict" function like Pydantic
dict_fn = getattr(o, "dict", None)
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

0 comments on commit de39f87

Please sign in to comment.