Skip to content

Commit

Permalink
Changed url names
Browse files Browse the repository at this point in the history
  • Loading branch information
northpowered committed May 3, 2023
1 parent 003f4d7 commit 53319d9
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 23 deletions.
36 changes: 25 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,35 @@ Args for endpoints:
**Activity execution**

```
*activity_name* - [string] - REQUIRED
*activity_task_queue* - [string] - REQUIRED
*args* - [ANY] - may be null
*start_to_close_timeout* - [int] - Default is 10
*execution_timeout* - [int] - Default is 10
*parent_workflow_id* - [string] - If null, UUID4 will be used
activity_name - [string] - REQUIRED
activity_task_queue - [string] - REQUIRED
args - [ANY] - may be null
start_to_close_timeout - [int] - Default is 10
schedule_to_start_timeout - [int] - may be null
heartbeat_timeout - [int] - may be null
schedule_to_close_timeout - [int] - may be null
retry_policy - [Object] - may be null
parent_workflow_id - [string] - If null, UUID4 will be used
parent_workflow_execution_timeout - [int] - Default is 10
parent_workflow_run_timeout - [int] - may be null
parent_workflow_task_timeout - [int] - may be null
# RetryPolicy object
initial_interval - [int] - Default is 1
backoff_coefficient - [float] - Default is 2
maximum_interval - [int] - may be null
maximum_attempts - [int] - Default is 0
```


**Workflow execution**
```
*workflow_name* - [string] - REQUIRED
*workflow_task_queue* - [string] - REQUIRED
*args* - [ANY] - may be null
*execution_timeout* - [int] - Default is 10
*workfloCODECOV_TOKENw_id* - [string] - If null, UUID4 will be used
workflow_name - [string] - REQUIRED
workflow_task_queue - [string] - REQUIRED
args - [ANY] - may be null
execution_timeout - [int] - Default is 10
workflow_id- [string] - If null, UUID4 will be used
```
### Run

Expand Down
8 changes: 6 additions & 2 deletions src/executor/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
PROMETHEUS_ENDPOINT_PORT
)
from contextlib import asynccontextmanager
from .router import execution_router
from .router import (
workflow_router,
activity_router
)
from rich.console import Console


Expand Down Expand Up @@ -63,4 +66,5 @@ async def lifespan(app: FastAPI): # pragma: no cover
)


app.include_router(execution_router)
app.include_router(workflow_router)
app.include_router(activity_router)
26 changes: 19 additions & 7 deletions src/executor/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ def __init__(self, version: APIVersion | None = None, **kwargs): # pragma: no c
self.prefix = f"/v{version}{self.prefix}"


execution_router = APIRouter(
prefix="/execution",
tags=["Temporal execution"],
activity_router = APIRouter(
prefix="/activity",
tags=["Activities"],
responses={
404: {"description": "URL not found"},
400: {"description": "Bad request"},
Expand All @@ -32,15 +32,27 @@ def __init__(self, version: APIVersion | None = None, **kwargs): # pragma: no c
)


execution_router.add_api_route(
"/activity",
workflow_router = APIRouter(
prefix="/workflow",
tags=["Workflows"],
responses={
404: {"description": "URL not found"},
400: {"description": "Bad request"},
},
version=APIVersion(1),
)


activity_router.add_api_route(
"/execute",
activity_execution,
summary="Execute any activity in the namespace",
methods=["post"],
)

execution_router.add_api_route(
"/workflow",

workflow_router.add_api_route(
"/execute",
workflow_execution,
summary="Execute any workflow in the namespace",
methods=["post"],
Expand Down
13 changes: 13 additions & 0 deletions src/tests/misc_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from executor.common import schedule_timeout_from_request
from datetime import timedelta


def test_schedule_timeout_builder():

assert schedule_timeout_from_request(None) is None
assert schedule_timeout_from_request(3) == timedelta(seconds=3)
assert schedule_timeout_from_request("3") == timedelta(seconds=3)
try:
schedule_timeout_from_request("foo")
except Exception as ex:
assert isinstance(ex, ValueError)
4 changes: 2 additions & 2 deletions src/tests/temporal_endpoint_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def test_a_endpoint(t_client: Client):
args={"str_1": "q", "str_2": "w"},
start_to_close_timeout=10,
parent_workflow_id="pytest-parent-workflow",
execution_timeout=4,
parent_workflow_execution_timeout=4,
)
resp: ExecutionResult = await activity_execution(
client=t_client, payload=payload
Expand All @@ -51,7 +51,7 @@ async def test_a_endpoint_rand_id(t_client: Client):
args={"str_1": "q", "str_2": "w"},
start_to_close_timeout=10,
parent_workflow_id=None,
execution_timeout=4,
parent_workflow_execution_timeout=4,
)
resp: ExecutionResult = await activity_execution(
client=t_client, payload=payload
Expand Down
2 changes: 1 addition & 1 deletion src/tests/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def seq_arg_activity(str_1: str, str_2: str) -> str:

@activity.defn()
async def retry_activity(input: str) -> str:
#await asyncio.sleep(6)
# await asyncio.sleep(6)
return input + input


Expand Down

0 comments on commit 53319d9

Please sign in to comment.