This commit is contained in:
ahmed531998 2023-07-24 10:53:10 +02:00
parent dd24d723bd
commit 21a1a7a0b8
1 changed files with 60 additions and 41 deletions

19
main.py
View File

@ -32,9 +32,11 @@ cors = CORS(app, resources={r"/api/predict": {"origins": url},
r"/health": {"origins": "*"} r"/health": {"origins": "*"}
}) })
users = {} users = {}
alive = "alive"
def vre_fetch(): def vre_fetch():
while True: while True:
try:
time.sleep(1000) time.sleep(1000)
print('getting new material') print('getting new material')
#users[token]['args']['vre'].get_vre_update() #users[token]['args']['vre'].get_vre_update()
@ -45,32 +47,45 @@ def vre_fetch():
vre.index_periodic_update() vre.index_periodic_update()
rg.update_index(vre.get_index()) rg.update_index(vre.get_index())
rg.update_db(vre.get_db()) rg.update_db(vre.get_db())
except Exception as e:
alive = "dead_vre_fetch"
def user_interest_decay(token): def user_interest_decay(token):
while True: while True:
try:
if token in users: if token in users:
print("decaying interests after 3 minutes for " + users[token]['username']) print("decaying interests after 3 minutes for " + users[token]['username'])
time.sleep(180) time.sleep(180)
users[token]['user'].decay_interests() users[token]['user'].decay_interests()
else: else:
break break
except Exception as e:
alive = "dead_interest_decay"
def clear_inactive(): def clear_inactive():
while True: while True:
try:
time.sleep(1) time.sleep(1)
for username in users: for username in users:
if users[username]['activity'] > 3600: if users[username]['activity'] > 3600:
del users[username] del users[username]
users[username]['activity'] += 1 users[username]['activity'] += 1
except Exception as e:
alive = "dead_clear_inactive"
@app.route("/health", methods=['GET']) @app.route("/health", methods=['GET'])
def health(): def health():
if alive=="alive":
return "Success", 200 return "Success", 200
else:
return alive, 500
@app.route("/api/dm", methods=['POST']) @app.route("/api/dm", methods=['POST'])
def init_dm(): def init_dm():
try:
token = request.get_json().get("token") token = request.get_json().get("token")
status = request.get_json().get("stat") status = request.get_json().get("stat")
if status == "start": if status == "start":
@ -94,6 +109,10 @@ def init_dm():
else: else:
message = {"stat": "done"} message = {"stat": "done"}
return message return message
except Exception as e:
message = {"stat": "init_dm_error"}
return message
@app.route("/api/predict", methods=['POST']) @app.route("/api/predict", methods=['POST'])
def predict(): def predict():