-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.py
47 lines (41 loc) · 1.47 KB
/
entrypoint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import logging
import os
import sys
import time
import pyfiglet
import psycopg
from multiprocessing import Process, set_start_method
logging.basicConfig(level=logging.INFO, format="[%(asctime)s: %(levelname)s/StartingStageProcess] %(message)s")
def initializeTask():
def beat():
os.system("celery -A beats beat --loglevel=info")
beatProcess = Process(target=beat)
beatProcess.start()
beatProcess.join()
def checkDatabase():
logging.info("Checking database connection...")
import lib.config
conf = lib.config.Config()
connection = f"host={conf.postgresql['host']} port={conf.postgresql['port']} user={conf.postgresql['user']} password={conf.postgresql['password']} dbname={conf.postgresql['database']}"
try:
database = psycopg.connect(
conninfo=connection
)
curosr = database.cursor()
database.autocommit = True
curosr.execute("SELECT version();")
version = curosr.fetchall()
database.close()
logging.info(f"Database connection established: {version}")
except psycopg.OperationalError:
logging.error("Error: Unable to connect to database")
sys.exit(0)
if __name__ == "__main__":
# add delay to make sure the banner is displayed
font = pyfiglet.Figlet(direction="auto",width=60)
print(font.renderText("SSReborn"))
time.sleep(1)
if os.name == "nt":
set_start_method("spawn")
checkDatabase()
initializeTask()