-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_logger.py
40 lines (30 loc) · 1.03 KB
/
start_logger.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
import subprocess
# from threading import Thread
from flask import Flask, request
import json
import ngrok
from configs import *
app = Flask(__name__)
log_file_path = "server_log.json"
@app.route('/log', methods=['POST'])
def log_data():
data = request.json
print(f"[MACHINE {data['machine']} ] ==> {data['message']}")
with open(log_file_path, 'a') as log_file:
json.dump(data, log_file)
log_file.write('\n')
return 'Logged', 200
def start_ngrok(port=5020):
listener = ngrok.forward(port, authtoken=NGROK_AUTHTOKEN)
print(f"Ngrok tunnel established at: {listener.url()}")
with open('./azure_batch/ngrok_url.txt', 'w') as url_file:
url_file.write(listener.url())
# def start_ngrok_async(port=5020):
# ngrok_thread = Thread(target=start_ngrok, args=(port,))
# ngrok_thread.start()
PORT = 5020
# with app.app_context():
# start_ngrok_async(PORT)
if __name__ == "__main__":
start_ngrok(port=PORT)
app.run(debug=True, use_reloader=False, port=PORT)