Skip to content

Commit

Permalink
core: kraken: Add check for space prior to install
Browse files Browse the repository at this point in the history
* Add free space check in kraken prior to install extension
  • Loading branch information
JoaoMario109 authored and patrickelectric committed Mar 19, 2024
1 parent da29f5e commit b8e47d6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/services/kraken/kraken.py
Expand Up @@ -346,5 +346,13 @@ async def load_stats(self) -> Dict[str, Any]:
}
return result

def has_enough_disk_space(self, path: str = "/", required_mb: int = 2**10) -> bool:
try:
free_space = psutil.disk_usage(path).free
# Right now only check if there is 1GB of free space as a hardcoded value
return bool(free_space > required_mb * 2**20)
except FileNotFoundError:
return False

async def stop(self) -> None:
self.should_run = False
5 changes: 5 additions & 0 deletions core/services/kraken/main.py
Expand Up @@ -78,6 +78,11 @@ async def install_extension(extension: Extension) -> Any:
status_code=status.HTTP_400_BAD_REQUEST,
detail="Invalid extension description",
)
if not kraken.has_enough_disk_space():
raise HTTPException(
status_code=status.HTTP_507_INSUFFICIENT_STORAGE,
detail="Not enough disk space to install the extension",
)
return StreamingResponse(kraken.install_extension(extension))


Expand Down

0 comments on commit b8e47d6

Please sign in to comment.