Skip to content

Commit

Permalink
Support query for listing schedules (#581)
Browse files Browse the repository at this point in the history
Fixes #573
  • Loading branch information
cretz authored Jul 17, 2024
1 parent e409d32 commit 913b4b6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
7 changes: 7 additions & 0 deletions temporalio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@ def get_schedule_handle(self, id: str) -> ScheduleHandle:

async def list_schedules(
self,
query: Optional[str] = None,
*,
page_size: int = 1000,
next_page_token: Optional[bytes] = None,
Expand All @@ -982,6 +983,9 @@ async def list_schedules(
Args:
page_size: Maximum number of results for each page.
query: A Temporal visibility list filter. See Temporal documentation
concerning visibility list filters including behavior when left
unset.
next_page_token: A previously obtained next page token if doing
pagination. Usually not needed as the iterator automatically
starts from the beginning.
Expand All @@ -998,6 +1002,7 @@ async def list_schedules(
next_page_token=next_page_token,
rpc_metadata=rpc_metadata,
rpc_timeout=rpc_timeout,
query=query,
)
)

Expand Down Expand Up @@ -4195,6 +4200,7 @@ async def fetch_next_page(self, *, page_size: Optional[int] = None) -> None:
namespace=self._client.namespace,
maximum_page_size=page_size or self._input.page_size,
next_page_token=self._next_page_token or b"",
query=self._input.query or "",
),
retry=True,
metadata=self._input.rpc_metadata,
Expand Down Expand Up @@ -4704,6 +4710,7 @@ class ListSchedulesInput:
next_page_token: Optional[bytes]
rpc_metadata: Mapping[str, str]
rpc_timeout: Optional[timedelta]
query: Optional[str] = None


@dataclass
Expand Down
25 changes: 23 additions & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,10 +909,20 @@ async def update_desc_get_action_count() -> int:
)

# Create 4 more schedules of the same type and confirm they are in list
# eventually
# eventually. Two of them we will create with search attributes.
keyword_attr_key = SearchAttributeKey.for_keyword("python-test-schedule-keyword")
await ensure_search_attributes_present(client, keyword_attr_key)
expected_ids = [handle.id]
for i in range(4):
new_handle = await client.create_schedule(f"{handle.id}-{i + 1}", desc.schedule)
new_handle = await client.create_schedule(
f"{handle.id}-{i + 1}",
desc.schedule,
search_attributes=TypedSearchAttributes(
[SearchAttributePair(keyword_attr_key, "some-schedule-attr")]
)
if i >= 2
else None,
)
expected_ids.append(new_handle.id)

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

await assert_eq_eventually(expected_ids, list_ids)

# Now do a list w/ query for certain search attributes and confirm
list_descs = [
d
async for d in await client.list_schedules(
"`python-test-schedule-keyword` = 'some-schedule-attr'"
)
]
assert len(list_descs) == 2
assert list_descs[0].id in [f"{handle.id}-3", f"{handle.id}-4"]
assert list_descs[1].id in [f"{handle.id}-3", f"{handle.id}-4"]

# Delete all of the schedules
for id in await list_ids():
await client.get_schedule_handle(id).delete()
Expand Down

0 comments on commit 913b4b6

Please sign in to comment.