Skip to content

Commit f91c925

Browse files
authored
chore: add ruff format check (#43)
<!-- Describe what has changed in this PR --> **What changed?** * add ruff format check in makefile and CI <!-- Tell your future self why have you made these changes --> **Why?** Format is important <!-- How have you verified this change? Tested locally? Added a unit test? Checked in staging env? --> **How did you test it?** <!-- Assuming the worst case, what can be broken when deploying this change to production? --> **Potential risks** <!-- Is it notable for release? e.g. schema updates, configuration or data migration required? If so, please mention it, and also update CHANGELOG.md --> **Release notes** <!-- Is there any documentation updates should be made for config, https://cadenceworkflow.io/docs/operation-guide/setup/ ? If so, please open an PR in https://github.com/cadence-workflow/cadence-docs --> **Documentation Changes** --------- Signed-off-by: Shijie Sheng <[email protected]>
1 parent 2121489 commit f91c925

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2335
-1421
lines changed

.github/workflows/ci_checks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jobs:
3434
- name: Run Ruff linter
3535
run: |
3636
uv tool run ruff check
37+
uv tool run ruff format --check
3738
3839
type-check:
3940
name: Type Safety Check

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ generate:
1818
lint:
1919
@echo "Running Ruff linter and fixing lint issues..."
2020
uv tool run ruff check --fix
21+
uv tool run ruff format
2122

2223
# Run type checker
2324
type-check:
@@ -52,4 +53,3 @@ help:
5253
@echo " make integration-test - Run integration tests"
5354
@echo " make clean - Remove generated files and caches"
5455
@echo " make help - Show this help message"
55-

cadence/_internal/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,3 @@
66
"""
77

88
__all__: list[str] = []
9-
10-

cadence/_internal/activity/__init__.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
2-
3-
from ._activity_executor import (
4-
ActivityExecutor
5-
)
1+
from ._activity_executor import ActivityExecutor
62

73
__all__ = [
84
"ActivityExecutor",

cadence/_internal/activity/_activity_executor.py

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,33 @@
88
from cadence._internal.activity._context import _Context, _SyncContext
99
from cadence.activity import ActivityInfo, ActivityDefinition, ExecutionStrategy
1010
from cadence.api.v1.common_pb2 import Failure
11-
from cadence.api.v1.service_worker_pb2 import PollForActivityTaskResponse, RespondActivityTaskFailedRequest, \
12-
RespondActivityTaskCompletedRequest
11+
from cadence.api.v1.service_worker_pb2 import (
12+
PollForActivityTaskResponse,
13+
RespondActivityTaskFailedRequest,
14+
RespondActivityTaskCompletedRequest,
15+
)
1316
from cadence.client import Client
1417

1518
_logger = getLogger(__name__)
1619

20+
1721
class ActivityExecutor:
18-
def __init__(self, client: Client, task_list: str, identity: str, max_workers: int, registry: Callable[[str], ActivityDefinition]):
22+
def __init__(
23+
self,
24+
client: Client,
25+
task_list: str,
26+
identity: str,
27+
max_workers: int,
28+
registry: Callable[[str], ActivityDefinition],
29+
):
1930
self._client = client
2031
self._data_converter = client.data_converter
2132
self._registry = registry
2233
self._identity = identity
2334
self._task_list = task_list
24-
self._thread_pool = ThreadPoolExecutor(max_workers=max_workers,
25-
thread_name_prefix=f'{task_list}-activity-')
35+
self._thread_pool = ThreadPoolExecutor(
36+
max_workers=max_workers, thread_name_prefix=f"{task_list}-activity-"
37+
)
2638

2739
async def execute(self, task: PollForActivityTaskResponse):
2840
try:
@@ -46,27 +58,33 @@ def _create_context(self, task: PollForActivityTaskResponse) -> _Context:
4658
else:
4759
return _SyncContext(self._client, info, activity_def, self._thread_pool)
4860

49-
async def _report_failure(self, task: PollForActivityTaskResponse, error: Exception):
61+
async def _report_failure(
62+
self, task: PollForActivityTaskResponse, error: Exception
63+
):
5064
try:
51-
await self._client.worker_stub.RespondActivityTaskFailed(RespondActivityTaskFailedRequest(
52-
task_token=task.task_token,
53-
failure=_to_failure(error),
54-
identity=self._identity,
55-
))
65+
await self._client.worker_stub.RespondActivityTaskFailed(
66+
RespondActivityTaskFailedRequest(
67+
task_token=task.task_token,
68+
failure=_to_failure(error),
69+
identity=self._identity,
70+
)
71+
)
5672
except Exception:
57-
_logger.exception('Exception reporting activity failure')
73+
_logger.exception("Exception reporting activity failure")
5874

5975
async def _report_success(self, task: PollForActivityTaskResponse, result: Any):
6076
as_payload = await self._data_converter.to_data([result])
6177

6278
try:
63-
await self._client.worker_stub.RespondActivityTaskCompleted(RespondActivityTaskCompletedRequest(
64-
task_token=task.task_token,
65-
result=as_payload,
66-
identity=self._identity,
67-
))
79+
await self._client.worker_stub.RespondActivityTaskCompleted(
80+
RespondActivityTaskCompletedRequest(
81+
task_token=task.task_token,
82+
result=as_payload,
83+
identity=self._identity,
84+
)
85+
)
6886
except Exception:
69-
_logger.exception('Exception reporting activity complete')
87+
_logger.exception("Exception reporting activity complete")
7088

7189
def _create_info(self, task: PollForActivityTaskResponse) -> ActivityInfo:
7290
return ActivityInfo(

cadence/_internal/activity/_context.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88

99

1010
class _Context(ActivityContext):
11-
def __init__(self, client: Client, info: ActivityInfo, activity_fn: ActivityDefinition[[Any], Any]):
11+
def __init__(
12+
self,
13+
client: Client,
14+
info: ActivityInfo,
15+
activity_fn: ActivityDefinition[[Any], Any],
16+
):
1217
self._client = client
1318
self._info = info
1419
self._activity_fn = activity_fn
@@ -28,8 +33,15 @@ def client(self) -> Client:
2833
def info(self) -> ActivityInfo:
2934
return self._info
3035

36+
3137
class _SyncContext(_Context):
32-
def __init__(self, client: Client, info: ActivityInfo, activity_fn: ActivityDefinition[[Any], Any], executor: ThreadPoolExecutor):
38+
def __init__(
39+
self,
40+
client: Client,
41+
info: ActivityInfo,
42+
activity_fn: ActivityDefinition[[Any], Any],
43+
executor: ThreadPoolExecutor,
44+
):
3345
super().__init__(client, info, activity_fn)
3446
self._executor = executor
3547

@@ -44,4 +56,3 @@ def _run(self, args: list[Any]) -> Any:
4456

4557
def client(self) -> Client:
4658
raise RuntimeError("client is only supported in async activities")
47-

0 commit comments

Comments
 (0)