feat: add wait_until_database_online helper for knowledge base databa…#70
Closed
cipheraxat wants to merge 1 commit intodigitalocean:mainfrom
Closed
feat: add wait_until_database_online helper for knowledge base databa…#70cipheraxat wants to merge 1 commit intodigitalocean:mainfrom
cipheraxat wants to merge 1 commit intodigitalocean:mainfrom
Conversation
…se polling - Add wait_until_database_online method to KnowledgeBasesResource and AsyncKnowledgeBasesResource - Polls knowledge base database_status until it reaches ONLINE or encounters terminal failure - Implements configurable timeout and poll_interval parameters - Add two new exception types: KnowledgeBaseDatabaseError and KnowledgeBaseDatabaseTimeoutError - Expose new method through WithRawResponse and WithStreamingResponse wrappers - Add comprehensive unit tests (8 tests: 4 sync + 4 async) covering success, timeout, failure, and validation scenarios - Follows the same pattern as agents.wait_until_ready for consistency Closes digitalocean#42
Collaborator
|
Closing as a dupe of #49 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR implements
wait_until_database_online()method for polling knowledge base database creation status, following the established pattern ofagents.wait_until_ready().Changes Made
1. New Exception Classes (
src/gradient/_exceptions.py)Added two new exception types for database polling:
KnowledgeBaseDatabaseError: Raised when database creation fails with terminal statusKnowledgeBaseDatabaseTimeoutError: Raised when polling exceeds timeout limitBoth exceptions store relevant identifiers for debugging:
statusattribute onKnowledgeBaseDatabaseErrorknowledge_base_idattribute onKnowledgeBaseDatabaseTimeoutError2. Resource Methods (
src/gradient/resources/knowledge_bases/knowledge_bases.py)Synchronous Method
Asynchronous Method
Behavior:
retrieve(uuid)untildatabase_status == "ONLINE"KnowledgeBaseRetrieveResponseKnowledgeBaseDatabaseErroron terminal status ("DECOMMISSIONED", "UNHEALTHY")KnowledgeBaseDatabaseTimeoutErrorif exceededValueErroron empty UUID3. Wrapper Classes
Updated all four wrapper classes to expose the new method:
KnowledgeBasesResourceWithRawResponseAsyncKnowledgeBasesResourceWithRawResponseKnowledgeBasesResourceWithStreamingResponseAsyncKnowledgeBasesResourceWithStreamingResponseEnables usage patterns:
4. Comprehensive Tests (
tests/api_resources/test_knowledge_bases.py)Synchronous Tests (4):
test_method_wait_until_database_online: Success path with status progressiontest_wait_until_database_online_timeout: Timeout handlingtest_wait_until_database_online_failed: Failure status handling (UNHEALTHY)test_wait_until_database_online_empty_uuid: Input validationAsynchronous Tests (4):
Test Characteristics:
respx_mockto simulate server responsesagents.wait_until_readytestsImplementation Details
Polling Logic
Key Design Decisions
agents.wait_until_ready()for familiarityextra_headers,extra_query,extra_bodyfor consistencyTesting & Validation
✓ Code Quality Checks
✓ Functional Tests
✓ Integration
import timefor polling functionalityimport httpxfor test mock responsesFiles Modified
src/gradient/_exceptions.py- Added 2 exception classessrc/gradient/resources/knowledge_bases/knowledge_bases.py- Added sync/async methods + wrapperstests/api_resources/test_knowledge_bases.py- Added 8 unit teststests/api_resources/test_agents.py,examples/agent_wait_until_ready.pyCommit Information
feat: add wait_until_database_online helper for knowledge base database pollingUsage Example
Async Example
Related Issue
Closes #42