comments added
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Füleki Fábián 2020-04-04 13:53:26 +02:00
parent 2376c1355d
commit 60c6698495
3 changed files with 13 additions and 6 deletions

View File

@ -8,6 +8,8 @@ from flask_classful import FlaskView
class ConsumersView(FlaskView): class ConsumersView(FlaskView):
def get(self): def get(self):
# load the currently available consumer list from the redis database
consumer_list = json.loads((redis_client.get("consumer_list") or b"{}").decode('utf-8')) consumer_list = json.loads((redis_client.get("consumer_list") or b"{}").decode('utf-8'))
current_app.logger.warning(jsonify([v['ip'] for k, v in consumer_list.items()]))
# jsonify and return the list of active consumers
return jsonify([v['ip'] for k, v in consumer_list.items()]) return jsonify([v['ip'] for k, v in consumer_list.items()])

View File

@ -5,5 +5,8 @@ from flask_classful import FlaskView
class LogView(FlaskView): class LogView(FlaskView):
def post(self): def post(self):
# display received message
current_app.logger.info(f"New message: {request.json['message']}") current_app.logger.info(f"New message: {request.json['message']}")
# return HTTP 204 - No content message
return Response(status = 204) return Response(status = 204)

View File

@ -1,7 +1,7 @@
import json import json
from flask import request, current_app, jsonify from flask import request, current_app, jsonify
from flask_classful import FlaskView from flask_classful import FlaskView
from db import redis_client # ez nagyon otvar from db import redis_client
class SyncView(FlaskView): class SyncView(FlaskView):
@ -10,23 +10,25 @@ class SyncView(FlaskView):
remote_uuid = request.json['uuid'] remote_uuid = request.json['uuid']
remote_ip = request.remote_addr remote_ip = request.remote_addr
# load the currently available consumer list from the redis database
consumer_list = json.loads((redis_client.get("consumer_list") or b"{}").decode('utf-8')) consumer_list = json.loads((redis_client.get("consumer_list") or b"{}").decode('utf-8'))
# Log something about it
if remote_uuid not in consumer_list.keys(): if remote_uuid not in consumer_list.keys():
# display newly registered consumer
current_app.logger.info(f"New consumer registered (unknown UUID): {remote_uuid} at {remote_ip}") current_app.logger.info(f"New consumer registered (unknown UUID): {remote_uuid} at {remote_ip}")
else: # known else:
if consumer_list[remote_uuid]['ip'] != remote_ip: if consumer_list[remote_uuid]['ip'] != remote_ip:
# log address changes
current_app.logger.info(f"Address of consumer {remote_uuid} changed to {remote_ip}") current_app.logger.info(f"Address of consumer {remote_uuid} changed to {remote_ip}")
# update consumer list redis databasse
consumer_list.update( consumer_list.update(
{remote_uuid: {"ip": remote_ip}} {remote_uuid: {"ip": remote_ip}}
) )
redis_client.set("consumer_list", json.dumps(consumer_list).encode('utf-8')) redis_client.set("consumer_list", json.dumps(consumer_list).encode('utf-8'))
# return with the current UUID
response = { response = {
"uuid": current_app.config['LOCAL_UUID'] "uuid": current_app.config['LOCAL_UUID']
} }
return jsonify(response) return jsonify(response)