This repository has been archived on 2020-09-24. You can view files and clone it, but cannot push or open issues or pull requests.
consumer-api/consumer_api/views/consumers_view.py
marcsello bb22760426
All checks were successful
continuous-integration/drone/push Build is passing
added option to get full consumers info
2020-04-22 02:45:57 +02:00

19 lines
563 B
Python

import json
from db import redis_client
from flask import jsonify, request
from flask_classful import FlaskView
class ConsumersView(FlaskView):
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'))
# jsonify and return the list of active consumers
if 'full' in request.args:
return jsonify(consumer_list)
else:
return jsonify([v['ip'] for k, v in consumer_list.items()])