-
Notifications
You must be signed in to change notification settings - Fork 1
/
collect_goreplay.py
46 lines (30 loc) · 1016 Bytes
/
collect_goreplay.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
import json
import os
from datetime import date
from flask import Flask, request
from config import csv_config, redis_config
from core.common import config
from src.database.writer import CsvWriter, RedisWriter
from src.entry.response import GoreplayReceive
app = Flask(__name__)
@app.route(config.FORWARD_PATH, methods=['POST'])
def endpoint():
dispatch(json.dumps(request.get_json()))
return "Done"
def dispatch(message: str):
# save_long_running(message)
save_to_daily_file(message)
def save_long_running(message: str):
w = RedisWriter()
if not w.ready():
return
w.insert_goreplay(redis_config["long_running"], message)
def save_to_daily_file(message: str):
writer = CsvWriter(csv_config["goreplay_data_dir_name"] + os.sep)
if not writer.ready():
return
receive = GoreplayReceive()
receive.message = message
writer.insert(str(date.today()), receive)
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=False, threaded=True)