-
Notifications
You must be signed in to change notification settings - Fork 782
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d90654b
commit bb6452f
Showing
11 changed files
with
190 additions
and
78 deletions.
There are no files selected for viewing
This file contains 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 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,58 @@ | ||
|
||
|
||
import sys | ||
|
||
# It's a dirty hack to exclude current directory from sys.path | ||
# to avoid importing "logging.py" located in the same directory | ||
# instead of the standard library "logging" module. | ||
# TODO: rename logging.py | ||
for i in range(0, len(sys.path)): | ||
if "keep/api" in sys.path[i]: | ||
sys.path.pop(i) | ||
break | ||
|
||
import os | ||
import time | ||
import logging | ||
import requests | ||
|
||
from keep.api.core.demo_mode import launch_demo_mode | ||
from keep.api.core.report_uptime import launch_uptime_reporting | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def main(): | ||
logger.info("Starting background server jobs.") | ||
|
||
# We intentionally don't use KEEP_API_URL here to avoid going through the internet. | ||
# Demo mode should be launched in the same environment as the server. | ||
keep_api_url = "http://localhost:" + str(os.environ.get("PORT", 8080)) | ||
|
||
while True: | ||
try: | ||
logger.info(f"Checking if server is up at {keep_api_url}...") | ||
response = requests.get(keep_api_url) | ||
response.raise_for_status() | ||
break | ||
except requests.exceptions.RequestException: | ||
logger.info("API is not up yet. Waiting...") | ||
time.sleep(5) | ||
|
||
threads = [] | ||
threads.append(launch_demo_mode(keep_api_url)) | ||
threads.append(launch_uptime_reporting()) | ||
|
||
for thread in threads: | ||
if thread is not None: | ||
thread.join() | ||
|
||
logger.info("Background server jobs started.") | ||
|
||
|
||
if __name__ == "__main__": | ||
""" | ||
This script should be executed alongside to the server. | ||
Running it in the same process as the server may (and most probably will) cause issues. | ||
""" | ||
main() |
This file contains 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 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 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 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
38 changes: 38 additions & 0 deletions
38
keep/api/models/db/migrations/versions/2024-11-20-15-50_192157fd5788.py
This file contains 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,38 @@ | ||
"""system table | ||
Revision ID: 192157fd5788 | ||
Revises: 620b6c048091 | ||
Create Date: 2024-11-20 15:50:29.500867 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
import sqlalchemy_utils | ||
import sqlmodel | ||
from alembic import op | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "192157fd5788" | ||
down_revision = "620b6c048091" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"system", | ||
sa.Column("id", sqlmodel.sql.sqltypes.AutoString(), nullable=False), | ||
sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False), | ||
sa.Column("value", sqlmodel.sql.sqltypes.AutoString(), nullable=False), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table("system") | ||
# ### end Alembic commands ### |
This file contains 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,8 @@ | ||
|
||
from sqlmodel import Field, SQLModel | ||
|
||
|
||
class System(SQLModel, table=True): | ||
id: str = Field(primary_key=True) | ||
name: str | ||
value: str |
This file contains 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 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.