-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
asyncAsync client implementationAsync client implementationenhancementNew feature or requestNew feature or requestmetadata-apiMetadata API endpointsMetadata API endpoints
Description
User Story
As a developer using AsyncOFSC, I want to iterate over all workzones lazily so that I can process large datasets without loading everything into memory.
Description
Add a new async generator function get_all_workzones to the AsyncOFSMetadata class that yields individual Workzone objects one by one, fetching pages on demand.
Requirements
- Add
get_all_workzones(limit: int = 100) -> AsyncGenerator[Workzone, None]method - Use true Python async generator with
yield(lazy evaluation) - Reuse existing
get_workzones()internally for consistent error handling - Add import:
from collections.abc import AsyncGenerator - Add comprehensive tests
Implementation
async def get_all_workzones(
self,
limit: int = 100
) -> AsyncGenerator[Workzone, None]:
"""Async generator that yields all workzones one by one."""
offset = 0
has_more = True
while has_more:
response = await self.get_workzones(offset=offset, limit=limit)
for workzone in response.items:
yield workzone
has_more = response.hasMore or False
offset += len(response.items)
if len(response.items) == 0:
breakUsage Example
async with AsyncOFSC(...) as client:
async for workzone in client.metadata.get_all_workzones():
print(workzone.workZoneLabel)
# Or collect all into a list
all_workzones = [wz async for wz in client.metadata.get_all_workzones()]Files to Modify
ofsc/async_client/metadata.py- Add method and importtests/async/test_async_workzones.py- Add test classTestAsyncGetAllWorkzones
Test Cases
test_get_all_workzones_returns_async_generator- Verify return typetest_get_all_workzones_yields_workzone_instances- Verify yielded itemstest_get_all_workzones_fetches_all- Verify pagination workstest_get_all_workzones_unique_labels- Verify no duplicates
Acceptance Criteria
- Function yields individual
Workzoneobjects (not pages) - Pagination is handled automatically
- Errors propagate immediately (fail-fast)
- All tests pass
- Code verified with ruff
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
asyncAsync client implementationAsync client implementationenhancementNew feature or requestNew feature or requestmetadata-apiMetadata API endpointsMetadata API endpoints