-
Notifications
You must be signed in to change notification settings - Fork 43
Add prune and re-enqueue signal functionality #322
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
20 commits
Select commit
Hold shift + click to select a range
c9d18d7
Add prune and re-enqueue signal functionality
NiveditJain e6367af
Fix typos in logging messages and comments
NiveditJain bd0a898
Update state-manager/app/models/signal_models.py
NiveditJain fc9c14c
Update state-manager/app/controller/re_queue_after_singal.py
NiveditJain 4cc63fe
Update state-manager/app/controller/re_queue_after_singal.py
NiveditJain b6127ff
Update state-manager/app/controller/prune_signal.py
NiveditJain 87870b0
Refactor re-queue after signal functionality and update state model
NiveditJain 94d740f
Merge branch 'signals' of https://github.com/NiveditJain/exospherehos…
NiveditJain c689a8e
Added import for time module in re_queue_after_signal.py to support t…
NiveditJain 55a4754
Add unit tests for prune and re-enqueue signal functionality
NiveditJain e5d61d8
Refactor test imports for prune and re-enqueue signal unit tests
NiveditJain d84b6ab
Implement prune and requeue signal functionality
NiveditJain ced39b9
Add tests for PruneSingal and ReQueueAfterSingal functionality
NiveditJain b018b03
Fix signal naming inconsistencies and enhance signal functionality
NiveditJain 5d66297
Correct signal naming in tests and enhance exception handling
NiveditJain ef84f0c
Enhance validation in ReEnqueueAfterRequestModel tests
NiveditJain 74f51a6
Add Signals documentation and update navigation in mkdocs.yml
NiveditJain c13b530
Update prune_signal status check to validate against QUEUED state
NiveditJain 49e2eb4
fixed all failing tests
NiveditJain ea760a1
namespace check would be added as a seprate unit later to take care o…
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
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,32 @@ | ||
| from app.models.signal_models import PruneRequestModel, SignalResponseModel | ||
| from fastapi import HTTPException, status | ||
| from beanie import PydanticObjectId | ||
|
|
||
| from app.models.db.state import State | ||
| from app.models.state_status_enum import StateStatusEnum | ||
| from app.singletons.logs_manager import LogsManager | ||
|
|
||
| logger = LogsManager().get_logger() | ||
|
|
||
| async def prune_signal(namespace_name: str, state_id: PydanticObjectId, body: PruneRequestModel, x_exosphere_request_id: str) -> SignalResponseModel: | ||
|
NiveditJain marked this conversation as resolved.
|
||
|
|
||
| try: | ||
| logger.info(f"Recieved prune signal for state {state_id} for namespace {namespace_name}", x_exosphere_request_id=x_exosphere_request_id) | ||
|
|
||
| state = await State.find_one(State.id == state_id) | ||
|
NiveditJain marked this conversation as resolved.
|
||
|
|
||
| if not state: | ||
| raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="State not found") | ||
|
|
||
| if state.status != StateStatusEnum.CREATED: | ||
| raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="State is not created") | ||
|
NiveditJain marked this conversation as resolved.
Outdated
|
||
|
|
||
|
NiveditJain marked this conversation as resolved.
|
||
| state.status = StateStatusEnum.PRUNED | ||
| state.data = body.data | ||
|
NiveditJain marked this conversation as resolved.
|
||
| await state.save() | ||
|
|
||
| return SignalResponseModel(status=StateStatusEnum.PRUNED, enqueue_after=state.enqueue_after) | ||
|
|
||
|
NiveditJain marked this conversation as resolved.
Outdated
|
||
| except Exception as e: | ||
| logger.error(f"Error pruning state {state_id} for namespace {namespace_name}", x_exosphere_request_id=x_exosphere_request_id, error=e) | ||
| raise | ||
|
NiveditJain marked this conversation as resolved.
|
||
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,32 @@ | ||
| from app.models.signal_models import ReEnqueueAfterRequestModel, SignalResponseModel | ||
| from fastapi import HTTPException, status | ||
| from beanie import PydanticObjectId | ||
|
|
||
| from app.models.db.state import State | ||
| from app.models.state_status_enum import StateStatusEnum | ||
| from app.singletons.logs_manager import LogsManager | ||
|
|
||
| logger = LogsManager().get_logger() | ||
|
|
||
| async def re_queue_after_signal(namespace_name: str, state_id: PydanticObjectId, body: ReEnqueueAfterRequestModel, x_exosphere_request_id: str) -> SignalResponseModel: | ||
|
NiveditJain marked this conversation as resolved.
|
||
|
|
||
| try: | ||
| logger.info(f"Recieved re-queue after signal for state {state_id} for namespace {namespace_name}", x_exosphere_request_id=x_exosphere_request_id) | ||
|
|
||
| state = await State.find_one(State.id == state_id) | ||
|
NiveditJain marked this conversation as resolved.
|
||
|
|
||
| if not state: | ||
| raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="State not found") | ||
|
|
||
| if state.status != StateStatusEnum.CREATED: | ||
| raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="State is not created") | ||
|
|
||
| state.status = StateStatusEnum.CREATED | ||
|
NiveditJain marked this conversation as resolved.
|
||
| state.enqueue_after = state.enqueue_after + body.enqueue_after | ||
|
NiveditJain marked this conversation as resolved.
Outdated
|
||
| await state.save() | ||
|
|
||
| return SignalResponseModel(status=StateStatusEnum.CREATED, enqueue_after=state.enqueue_after) | ||
|
|
||
| except Exception as e: | ||
| logger.error(f"Error re-queueing state {state_id} for namespace {namespace_name}", x_exosphere_request_id=x_exosphere_request_id, error=e) | ||
| raise | ||
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
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,14 @@ | ||
| from pydantic import BaseModel, Field | ||
| from .state_status_enum import StateStatusEnum | ||
| from typing import Any | ||
|
|
||
|
|
||
| class SignalResponseModel(BaseModel): | ||
|
NiveditJain marked this conversation as resolved.
|
||
| enqueue_after: int = Field(..., description="Unix time in milliseconds after which the state should be re-enqueued") | ||
| status: StateStatusEnum = Field(..., description="Status of the state") | ||
|
NiveditJain marked this conversation as resolved.
|
||
|
|
||
|
NiveditJain marked this conversation as resolved.
|
||
| class PruneRequestModel(BaseModel): | ||
| data: dict[str, Any] = Field(..., description="Data of the state") | ||
|
|
||
|
NiveditJain marked this conversation as resolved.
|
||
| class ReEnqueueAfterRequestModel(BaseModel): | ||
| enqueue_after: int = Field(..., description="Unix time in milliseconds after which the state should be re-enqueued") | ||
|
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
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.