Skip to content

Add async generator get_all_workzones to AsyncOFSC #112

@btoron

Description

@btoron

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:
            break

Usage 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 import
  • tests/async/test_async_workzones.py - Add test class TestAsyncGetAllWorkzones

Test Cases

  1. test_get_all_workzones_returns_async_generator - Verify return type
  2. test_get_all_workzones_yields_workzone_instances - Verify yielded items
  3. test_get_all_workzones_fetches_all - Verify pagination works
  4. test_get_all_workzones_unique_labels - Verify no duplicates

Acceptance Criteria

  • Function yields individual Workzone objects (not pages)
  • Pagination is handled automatically
  • Errors propagate immediately (fail-fast)
  • All tests pass
  • Code verified with ruff

Metadata

Metadata

Assignees

No one assigned

    Labels

    asyncAsync client implementationenhancementNew feature or requestmetadata-apiMetadata API endpoints

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions