Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
longquanzheng committed Sep 13, 2023
1 parent bc59f8f commit 0513bc7
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 49 deletions.
3 changes: 1 addition & 2 deletions iwf/command_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
from dataclasses import dataclass
from typing import Any, Union

from iwf_api.types import Unset

from iwf.iwf_api.iwf_api.models import (
ChannelRequestStatus,
CommandResults as IdlCommandResults,
TimerStatus,
)
from iwf.iwf_api.iwf_api.types import Unset
from iwf.object_encoder import ObjectEncoder


Expand Down
2 changes: 1 addition & 1 deletion iwf/object_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
get_type_hints,
)

from iwf_api.types import Unset
from typing_extensions import Literal

from iwf.iwf_api.iwf_api.models import EncodedObject
from iwf.iwf_api.iwf_api.types import Unset

# StrEnum is available in 3.11+
if sys.version_info >= (3, 11):
Expand Down
12 changes: 6 additions & 6 deletions iwf/tests/test_basic_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from iwf.persistence import Persistence
from iwf.state_decision import StateDecision
from iwf.state_schema import StateSchema
from iwf.tests.worker_server import registry
from iwf.tests.worker_server import _registry, start_if_not_started
from iwf.workflow import ObjectWorkflow
from iwf.workflow_context import WorkflowContext
from iwf.workflow_state import T, WorkflowState
Expand Down Expand Up @@ -57,12 +57,12 @@ def get_workflow_states(self) -> StateSchema:
return StateSchema.with_starting_state(State1(), State2())


hello_wf = BasicWorkflow()
registry.add_workflow(hello_wf)
client = Client(registry)


def test_basic_workflow():
registry = start_if_not_started()
hello_wf = BasicWorkflow()
registry.add_workflow(hello_wf)
client = Client(_registry)

wf_id = f"{inspect.currentframe().f_code.co_name}-{time.time_ns()}"

client.start_workflow(BasicWorkflow, wf_id, 100, "input")
Expand Down
6 changes: 3 additions & 3 deletions iwf/tests/test_internal_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from iwf.persistence import Persistence
from iwf.state_decision import StateDecision
from iwf.state_schema import StateSchema
from iwf.tests.worker_server import registry
from iwf.tests.worker_server import _registry
from iwf.workflow import ObjectWorkflow
from iwf.workflow_context import WorkflowContext
from iwf.workflow_state import T, WorkflowState
Expand Down Expand Up @@ -120,8 +120,8 @@ def get_communication_schema(self) -> CommunicationSchema:


wf = InternalChannelWorkflow()
registry.add_workflow(wf)
client = Client(registry)
_registry.add_workflow(wf)
client = Client(_registry)


def test_internal_channel_workflow():
Expand Down
6 changes: 3 additions & 3 deletions iwf/tests/test_persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from iwf.persistence_schema import PersistenceField, PersistenceSchema
from iwf.state_decision import StateDecision
from iwf.state_schema import StateSchema
from iwf.tests.worker_server import registry
from iwf.tests.worker_server import _registry
from iwf.workflow import ObjectWorkflow
from iwf.workflow_context import WorkflowContext
from iwf.workflow_state import T, WorkflowState
Expand Down Expand Up @@ -61,8 +61,8 @@ def get_persistence_schema(self) -> PersistenceSchema:


wf = PersistenceWorkflow()
registry.add_workflow(wf)
client = Client(registry)
_registry.add_workflow(wf)
client = Client(_registry)


def test_persistence_workflow():
Expand Down
6 changes: 3 additions & 3 deletions iwf/tests/test_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from iwf.rpc import rpc
from iwf.state_decision import StateDecision
from iwf.state_schema import StateSchema
from iwf.tests.worker_server import registry
from iwf.tests.worker_server import _registry
from iwf.workflow import ObjectWorkflow
from iwf.workflow_context import WorkflowContext
from iwf.workflow_state import T, WorkflowState
Expand Down Expand Up @@ -100,8 +100,8 @@ class TestRPCs(unittest.TestCase):
@classmethod
def setUpClass(cls):
wf = RPCWorkflow()
registry.add_workflow(wf)
cls.client = Client(registry)
_registry.add_workflow(wf)
cls.client = Client(_registry)

def test_simple_rpc(self):
wf_id = f"{inspect.currentframe().f_code.co_name}-{time.time_ns()}"
Expand Down
6 changes: 3 additions & 3 deletions iwf/tests/test_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from iwf.persistence import Persistence
from iwf.state_decision import StateDecision
from iwf.state_schema import StateSchema
from iwf.tests.worker_server import registry
from iwf.tests.worker_server import _registry
from iwf.workflow import ObjectWorkflow
from iwf.workflow_context import WorkflowContext
from iwf.workflow_state import T, WorkflowState
Expand Down Expand Up @@ -78,8 +78,8 @@ class TestSignal(unittest.TestCase):
@classmethod
def setUpClass(cls):
wf = WaitSignalWorkflow()
registry.add_workflow(wf)
cls.client = Client(registry)
_registry.add_workflow(wf)
cls.client = Client(_registry)

def test_signal(self):
wf_id = f"{inspect.currentframe().f_code.co_name}-{time.time_ns()}"
Expand Down
6 changes: 3 additions & 3 deletions iwf/tests/test_state_failure_recovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from iwf.persistence import Persistence
from iwf.state_decision import StateDecision
from iwf.state_schema import StateSchema
from iwf.tests.worker_server import registry
from iwf.tests.worker_server import _registry
from iwf.workflow import ObjectWorkflow
from iwf.workflow_context import WorkflowContext
from iwf.workflow_state import T, WorkflowState
Expand Down Expand Up @@ -52,8 +52,8 @@ def get_workflow_states(self) -> StateSchema:


wf = RecoveryWorkflow()
registry.add_workflow(wf)
client = Client(registry)
_registry.add_workflow(wf)
client = Client(_registry)


class Test(unittest.TestCase):
Expand Down
6 changes: 3 additions & 3 deletions iwf/tests/test_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from iwf.persistence import Persistence
from iwf.state_decision import StateDecision
from iwf.state_schema import StateSchema
from iwf.tests.worker_server import registry
from iwf.tests.worker_server import _registry
from iwf.workflow import ObjectWorkflow
from iwf.workflow_context import WorkflowContext
from iwf.workflow_state import T, WorkflowState
Expand Down Expand Up @@ -45,8 +45,8 @@ def get_workflow_states(self) -> StateSchema:


wf = TimerWorkflow()
registry.add_workflow(wf)
client = Client(registry)
_registry.add_workflow(wf)
client = Client(_registry)


def test_timer_workflow():
Expand Down
6 changes: 3 additions & 3 deletions iwf/tests/test_workflow_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from iwf.state_decision import StateDecision
from iwf.state_schema import StateSchema
from iwf.stop_workflow_options import StopWorkflowOptions
from iwf.tests.worker_server import registry
from iwf.tests.worker_server import _registry
from iwf.workflow import ObjectWorkflow
from iwf.workflow_context import WorkflowContext
from iwf.workflow_state import T, WorkflowState
Expand Down Expand Up @@ -57,8 +57,8 @@ def get_workflow_states(self) -> StateSchema:


wf = WaitInternalChannelWorkflow()
registry.add_workflow(wf)
client = Client(registry)
_registry.add_workflow(wf)
client = Client(_registry)


class TestWorkflowErrors(unittest.TestCase):
Expand Down
17 changes: 14 additions & 3 deletions iwf/tests/worker_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

debug_mode: bool = False

registry = Registry()
_registry = Registry()

_flask_app = Flask(__name__)

_worker_service = WorkerService(registry)
_worker_service = WorkerService(_registry)


@_flask_app.route("/")
Expand Down Expand Up @@ -62,4 +62,15 @@ def internal_error(exception):
_webApp = Thread(target=_flask_app.run, args=("0.0.0.0", 8802))
# when debugging, keep the thread running so that we can see the error in history
_webApp.setDaemon(not debug_mode)
_webApp.start()

_started = False


def start_if_not_started() -> Registry:
global _started
global _registry
if _started:
return _registry
_started = True
_webApp.start()
return _registry
26 changes: 13 additions & 13 deletions iwf/unregistered_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,6 @@
from typing import Any, List, Optional, Type, TypeVar

from iwf_api import Client, errors
from iwf_api.api.default import (
post_api_v1_workflow_dataobjects_get,
post_api_v1_workflow_reset,
post_api_v1_workflow_rpc,
post_api_v1_workflow_search,
post_api_v1_workflow_searchattributes_get,
post_api_v1_workflow_signal,
post_api_v1_workflow_start,
post_api_v1_workflow_stop,
post_api_v1_workflow_timer_skip,
post_api_v_1_workflow_get_with_wait,
)
from iwf_api.types import Response

from iwf.client_options import ClientOptions
from iwf.errors import (
Expand All @@ -28,6 +15,18 @@
process_http_error,
process_workflow_abnormal_exit_error,
)
from iwf.iwf_api.iwf_api.api.default import (
post_api_v1_workflow_dataobjects_get,
post_api_v1_workflow_reset,
post_api_v1_workflow_rpc,
post_api_v1_workflow_search,
post_api_v1_workflow_searchattributes_get,
post_api_v1_workflow_signal,
post_api_v1_workflow_start,
post_api_v1_workflow_stop,
post_api_v1_workflow_timer_skip,
post_api_v_1_workflow_get_with_wait,
)
from iwf.iwf_api.iwf_api.models import (
EncodedObject,
ErrorResponse,
Expand Down Expand Up @@ -55,6 +54,7 @@
WorkflowStatus,
WorkflowStopRequest,
)
from iwf.iwf_api.iwf_api.types import Response
from iwf.reset_workflow_type_and_options import ResetWorkflowTypeAndOptions
from iwf.stop_workflow_options import StopWorkflowOptions

Expand Down
2 changes: 1 addition & 1 deletion iwf/utils/iwf_typing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Optional, TypeVar, Union

from iwf_api.types import Unset
from iwf.iwf_api.iwf_api.types import Unset

T = TypeVar("T")

Expand Down
3 changes: 1 addition & 2 deletions iwf/worker_service.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import typing
from dataclasses import dataclass

from iwf_api.types import Unset

from iwf.command_request import _to_idl_command_request
from iwf.command_results import from_idl_command_results
from iwf.communication import Communication
Expand All @@ -16,6 +14,7 @@
WorkflowWorkerRpcRequest,
WorkflowWorkerRpcResponse,
)
from iwf.iwf_api.iwf_api.types import Unset
from iwf.object_encoder import ObjectEncoder
from iwf.persistence import Persistence
from iwf.registry import Registry
Expand Down

0 comments on commit 0513bc7

Please sign in to comment.