Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. global timecheck
  2. app = Flask(__name__)
  3.  
  4. dbconn = mysql.connector.connect(host=config["mysql"]["host"],
  5. database=config["mysql"]["database"], user=config["mysql"]["user"],
  6. password=config["mysql"]["password"])
  7. cursor = dbconn.cursor()
  8.  
  9. def connect_to_db():
  10. query = ("update check_if_alive set check_time=%s")
  11. param = timecheck
  12. cursor.execute(query, (param,))
  13. print('Check_time: ' + str(param))
  14. dbconn.commit()
  15.  
  16. @app.route('/', methods=['GET', 'POST'])
  17. def aggregator():
  18. if request.method == 'POST':
  19. timecheck = datetime.datetime.now()
  20. #connect_to_db()
  21. return str('OK')
  22. else:
  23. print("lost connection to service")
  24.  
  25. if __name__ == '__main__':
  26. t = threading.Timer(30.0, connect_to_db)
  27. t.start()
  28. app.run(host="myhost", port=5211)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement