-
Notifications
You must be signed in to change notification settings - Fork 43
feat: add manual retry state apis #405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
844f13a
feat: add manual retry state functionality
NiveditJain 3d68362
fix: correct import path for manual retry state and update route defi…
NiveditJain edde4f0
fix: refine manual retry state error handling and query logic
NiveditJain 19b3a65
feat: add unit tests for manual retry state functionality
NiveditJain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| from pymongo.errors import DuplicateKeyError | ||
| from app.models.manual_retry import ManualRetryRequestModel, ManualRetryResponseModel | ||
| from beanie import PydanticObjectId | ||
| from app.singletons.logs_manager import LogsManager | ||
| from app.models.state_status_enum import StateStatusEnum | ||
| from fastapi import HTTPException, status | ||
| from app.models.db.state import State | ||
|
|
||
|
|
||
| logger = LogsManager().get_logger() | ||
|
|
||
| async def manual_retry_state(namespace_name: str, state_id: PydanticObjectId, body: ManualRetryRequestModel, x_exosphere_request_id: str): | ||
| try: | ||
| logger.info(f"Manual retry state {state_id} for namespace {namespace_name}", x_exosphere_request_id=x_exosphere_request_id) | ||
|
|
||
| state = await State.find_one(State.id == state_id) | ||
| if not state: | ||
| raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="State not found") | ||
|
NiveditJain marked this conversation as resolved.
Outdated
|
||
|
|
||
| try: | ||
| retry_state = State( | ||
| node_name=state.node_name, | ||
| namespace_name=state.namespace_name, | ||
| identifier=state.identifier, | ||
| graph_name=state.graph_name, | ||
| run_id=state.run_id, | ||
| status=StateStatusEnum.CREATED, | ||
| inputs=state.inputs, | ||
| outputs={}, | ||
| error=None, | ||
| parents=state.parents, | ||
| does_unites=state.does_unites, | ||
| fanout_id=body.fanout_id # this will ensure that multiple unwanted retries are not formed because of index in database | ||
| ) | ||
| retry_state = await retry_state.insert() | ||
|
NiveditJain marked this conversation as resolved.
|
||
| logger.info(f"Retry state {retry_state.id} created for state {state_id}", x_exosphere_request_id=x_exosphere_request_id) | ||
|
|
||
| state.status = StateStatusEnum.RETRY_CREATED | ||
| await state.save() | ||
|
|
||
| return ManualRetryResponseModel(id=str(retry_state.id), status=retry_state.status) | ||
| except DuplicateKeyError: | ||
| logger.info(f"Duplicate retry state detected for state {state_id}. A retry state with the same unique key already exists.", x_exosphere_request_id=x_exosphere_request_id) | ||
| raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Duplicate retry state detected") | ||
|
|
||
|
NiveditJain marked this conversation as resolved.
|
||
|
|
||
| except Exception as e: | ||
| logger.error(f"Error manual retry state {state_id} for namespace {namespace_name}", x_exosphere_request_id=x_exosphere_request_id) | ||
| raise e | ||
|
NiveditJain marked this conversation as resolved.
Outdated
NiveditJain marked this conversation as resolved.
Outdated
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| from pydantic import BaseModel, Field | ||
| from .state_status_enum import StateStatusEnum | ||
|
|
||
|
|
||
| class ManualRetryRequestModel(BaseModel): | ||
| fanout_id: str = Field(..., description="Fanout ID of the state") | ||
|
|
||
|
NiveditJain marked this conversation as resolved.
|
||
|
|
||
| class ManualRetryResponseModel(BaseModel): | ||
| id: str = Field(..., description="ID of the state") | ||
| status: StateStatusEnum = Field(..., description="Status of the state") | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.