Skip to content

Commit

Permalink
fix: a
Browse files Browse the repository at this point in the history
  • Loading branch information
talboren committed Nov 21, 2024
1 parent 2c311c5 commit b800578
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
extends:
file: docker-compose.common.yml
service: keep-backend-common
image: us-central1-docker.pkg.dev/keephq/keep/keep-api
image: us-central1-docker.pkg.dev/keephq/keep/keep-api:feat_clean-up
environment:
- AUTH_TYPE=NO_AUTH
volumes:
Expand Down
21 changes: 21 additions & 0 deletions keep/api/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging
import os
import threading
import time

import keep.api.logging
from keep.api.api import AUTH_TYPE
Expand All @@ -13,6 +15,21 @@
logger = logging.getLogger(__name__)


def log_memory_usage():
import psutil

process = psutil.Process() # Current process
memory_info = process.memory_info()
rss = memory_info.rss / 1024 / 1024 # Resident Set Size (in MB)
logger.info(f"Memory Usage: RSS = {rss:.2f} MB")


def memory_monitor():
while True:
log_memory_usage()
time.sleep(1) # Sleep for 1 minute


def on_starting(server=None):
"""This function is called by the gunicorn server when it starts"""
logger.info("Keep server starting")
Expand Down Expand Up @@ -53,4 +70,8 @@ def on_starting(server=None):
logger.info(f"ngrok tunnel: {public_url}")
os.environ["KEEP_API_URL"] = public_url

# Start the memory monitoring thread
memory_thread = threading.Thread(target=memory_monitor, daemon=True)
memory_thread.start()

logger.info("Keep server started")
7 changes: 3 additions & 4 deletions keep/providers/providers_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import json
import logging
import os
import sys
import types
import typing
from dataclasses import fields
Expand Down Expand Up @@ -388,9 +387,9 @@ def get_all_providers() -> list[Provider]:
)

# Unload the module
del sys.modules[
f"keep.providers.{provider_directory}.{provider_directory}"
]
# del sys.modules[
# f"keep.providers.{provider_directory}.{provider_directory}"
# ]
except ModuleNotFoundError:
logger.error(
f"Cannot import provider {provider_directory}, module not found."
Expand Down
32 changes: 31 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ ruff = "^0.1.6"
pytest-docker = "^2.0.1"

playwright = "^1.44.0"
psutil = "^6.1.0"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Expand Down

0 comments on commit b800578

Please sign in to comment.