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-scheduler/app.py
Füleki Fábián 0bea194f4a
Some checks reported errors
continuous-integration/drone/push Build was killed
Fixed timeout not being used
2020-05-08 23:00:37 +02:00

62 lines
1.6 KiB
Python

#!/usr/bin/env python3
import sentry_sdk
import time
import os
import logging
from redis_super_storage import RedisSuperStorage
from communicators import ConsumerCommunicator, ProducerCommunicator
from ip_watchdog import IPWatchdog
"""
Scheduler
"""
__author__ = "@kocsisr"
__copyright__ = "Copyright 2020, GoldenPogácsa Team"
__module_name__ = "app"
__version__text__ = "1"
sentry_sdk.init("https://0a106e104e114bc9a3fa47f9cb0db2f4@sentry.kmlabz.com/10")
def get_initial_ip_list():
ip_list = os.environ['INITIAL_SERVERS'].split(',')
logging.debug('Initial ip list ' + ", ".join(ip_list))
return ip_list
def main():
# set logging preferences
logging.basicConfig(filename='', level=logging.DEBUG)
redis_storage = RedisSuperStorage(os.environ.get('REDIS_URL', "redis://localhost:6379/0"),
os.environ.get("CUSTOMER_TIMEOUT", 30))
consumer_communicator = ConsumerCommunicator(redis_storage)
producer_communicator = ProducerCommunicator(redis_storage)
ip_watchdog = IPWatchdog(redis_storage)
logging.info("Syncing to initial consumer list")
for ip in get_initial_ip_list():
logging.debug(f"Syncing to {ip}")
consumer_communicator.targeted_snyc(ip)
while True:
logging.debug("Doing a sync")
consumer_communicator.sync_all()
ip_changed, ipaddr = ip_watchdog.ip_changed()
if ip_changed:
producer_communicator.push_ip_update(ipaddr)
time.sleep(int(os.environ.get("RUN_INTERVAL", 10)))
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
pass