Hello, i receive +- 20 post request and I am trying to save the data into my table but it is saving it many times. As you can see on the red line it seems to repeat itself, up to 4 times, and it adds "new" data from late POST request ( in blue ).
I also have this, but i'm not sur about how to use them . It looks like there is 4 "metrics collectors" and the data also repeat itself 4 times
And this is how i store my data, i just want to store only once the data i get in each new POST request
@app.route(webhook_url, methods=['POST'])
def index():
try:
data = request.json
fields_required = ["key","pair","price","timestamp"]
if not all(field in data for field in fields_required):
print("missing fields {0} on {1}".format(set(fields_required) - data.keys(), data))
return jsonify({
'message' : "missing fields {0} on {1}".format(set(fields_required) - data.keys(),data)
})
else:
return jsonify({"message":"All fields is fine"})
try:
if (data['key'] == "imagineifthiswasmypassword"):
print("Signal received {0} - {1}".format(data["pair"],data["timestamp"]))
new_job = Job(key=data['key'], pair=data['pair'], price=data['price'], timestamp=data['timestamp'])
try:
db.session.add(new_job)
db.session.commit()
except Exception as e:
print("Error adding job to database:", e)
db.session.rollback()
print("Signal mis dans totodb {0} - {1}".format(data["ticker"],data["timestamp"]))
else:
print('Pas bon key')
finally:
print('--->Finis du setup // finfin '+str(datetime.now()))
except BadRequest as e:
return 'Bad request: {}'.format(e)