Skip to content

Commit 913b4b6

Browse files
authored
Support query for listing schedules (#581)
Fixes #573
1 parent e409d32 commit 913b4b6

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

temporalio/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,7 @@ def get_schedule_handle(self, id: str) -> ScheduleHandle:
966966

967967
async def list_schedules(
968968
self,
969+
query: Optional[str] = None,
969970
*,
970971
page_size: int = 1000,
971972
next_page_token: Optional[bytes] = None,
@@ -982,6 +983,9 @@ async def list_schedules(
982983
983984
Args:
984985
page_size: Maximum number of results for each page.
986+
query: A Temporal visibility list filter. See Temporal documentation
987+
concerning visibility list filters including behavior when left
988+
unset.
985989
next_page_token: A previously obtained next page token if doing
986990
pagination. Usually not needed as the iterator automatically
987991
starts from the beginning.
@@ -998,6 +1002,7 @@ async def list_schedules(
9981002
next_page_token=next_page_token,
9991003
rpc_metadata=rpc_metadata,
10001004
rpc_timeout=rpc_timeout,
1005+
query=query,
10011006
)
10021007
)
10031008

@@ -4195,6 +4200,7 @@ async def fetch_next_page(self, *, page_size: Optional[int] = None) -> None:
41954200
namespace=self._client.namespace,
41964201
maximum_page_size=page_size or self._input.page_size,
41974202
next_page_token=self._next_page_token or b"",
4203+
query=self._input.query or "",
41984204
),
41994205
retry=True,
42004206
metadata=self._input.rpc_metadata,
@@ -4704,6 +4710,7 @@ class ListSchedulesInput:
47044710
next_page_token: Optional[bytes]
47054711
rpc_metadata: Mapping[str, str]
47064712
rpc_timeout: Optional[timedelta]
4713+
query: Optional[str] = None
47074714

47084715

47094716
@dataclass

tests/test_client.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -909,10 +909,20 @@ async def update_desc_get_action_count() -> int:
909909
)
910910

911911
# Create 4 more schedules of the same type and confirm they are in list
912-
# eventually
912+
# eventually. Two of them we will create with search attributes.
913+
keyword_attr_key = SearchAttributeKey.for_keyword("python-test-schedule-keyword")
914+
await ensure_search_attributes_present(client, keyword_attr_key)
913915
expected_ids = [handle.id]
914916
for i in range(4):
915-
new_handle = await client.create_schedule(f"{handle.id}-{i + 1}", desc.schedule)
917+
new_handle = await client.create_schedule(
918+
f"{handle.id}-{i + 1}",
919+
desc.schedule,
920+
search_attributes=TypedSearchAttributes(
921+
[SearchAttributePair(keyword_attr_key, "some-schedule-attr")]
922+
)
923+
if i >= 2
924+
else None,
925+
)
916926
expected_ids.append(new_handle.id)
917927

918928
async def list_ids() -> List[str]:
@@ -925,6 +935,17 @@ async def list_ids() -> List[str]:
925935

926936
await assert_eq_eventually(expected_ids, list_ids)
927937

938+
# Now do a list w/ query for certain search attributes and confirm
939+
list_descs = [
940+
d
941+
async for d in await client.list_schedules(
942+
"`python-test-schedule-keyword` = 'some-schedule-attr'"
943+
)
944+
]
945+
assert len(list_descs) == 2
946+
assert list_descs[0].id in [f"{handle.id}-3", f"{handle.id}-4"]
947+
assert list_descs[1].id in [f"{handle.id}-3", f"{handle.id}-4"]
948+
928949
# Delete all of the schedules
929950
for id in await list_ids():
930951
await client.get_schedule_handle(id).delete()

0 commit comments

Comments
 (0)