Skip to content

Commit

Permalink
Moving bg tasks out of the server
Browse files Browse the repository at this point in the history
  • Loading branch information
Matvey-Kuk committed Nov 20, 2024
1 parent ddcfcdf commit 85b1d89
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
1 change: 1 addition & 0 deletions docker/Dockerfile.dev.api
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ ENV PYTHONPATH="/app:${PYTHONPATH}"
ENV PATH="/venv/bin:${PATH}"
ENV VIRTUAL_ENV="/venv"

ENTRYPOINT ["/app/keep/entrypoint_backend.sh"]

CMD ["gunicorn", "keep.api.api:get_app", "--bind" , "0.0.0.0:8080" , "--workers", "1" , "-k" , "uvicorn.workers.UvicornWorker", "-c", "./keep/api/config.py", "--reload"]
9 changes: 0 additions & 9 deletions keep/api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,3 @@ def on_starting(server=None):
os.environ["KEEP_API_URL"] = public_url

logger.info("Keep server started")

launch_uptime_reporting()

if LIVE_DEMO_MODE:
logger.info("Launching Keep in demo mode.")
from keep.api.core.demo_mode_runner import launch_demo_mode
launch_demo_mode()
else:
logger.info("Not launching Keep in demo mode.")
8 changes: 0 additions & 8 deletions keep/api/core/demo_mode_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,11 @@
from keep.api.tasks.process_topology_task import process_topology
from keep.api.utils.tenant_utils import get_or_create_api_key
from keep.providers.providers_factory import ProvidersFactory
# import json

logging.config.dictConfig(CONFIG)

logger = logging.getLogger(__name__)

# file_path = '/Users/matvey/Desktop/keep-oss/keep/pr.json'
# def read_json_file(file_path):
# with open(file_path, 'r') as file:
# return json.load(file)
# pr_json = read_json_file(file_path)

correlation_rules_to_create = [
{
"sqlQuery": {"sql": "((name like :name_1))", "params": {"name_1": "%mq%"}},
Expand Down Expand Up @@ -353,7 +346,6 @@ def simulate_alerts(
time.sleep(5)

existing_installed_providers = get_existing_installed_providers(keep_api_key, keep_api_url)
# existing_installed_providers = pr_json['installed_providers']
logger.info(f"Existing installed providers: {existing_installed_providers}")
existing_providers_to_their_ids = {}
for existing_provider in existing_installed_providers:
Expand Down
10 changes: 10 additions & 0 deletions keep/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import sys
import typing
import time
import uuid
from collections import OrderedDict
from importlib import metadata
Expand Down Expand Up @@ -1627,5 +1628,14 @@ def start(self):
os._exit(0)


@cli.command()
@pass_info
def background_server_jobs(info: Info):
"""Run background jobs, expected to be running in parallel with the server."""
while True:
time.sleep(1)
logger.info("Background job running")
logger.info(os.environ)

if __name__ == "__main__":
cli(auto_envvar_prefix="KEEP")
13 changes: 13 additions & 0 deletions keep/entrypoint_backend.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

# Exit immediately if a command exits with a non-zero status
set -e

# Print commands and their arguments as they are executed
set -x

# Execute background taasks
poetry run python keep/cli/cli.py background-server-jobs &

# Execute the CMD provided in the Dockerfile or as arguments
exec "$@"

0 comments on commit 85b1d89

Please sign in to comment.