Added some docstrings
This commit is contained in:
parent
108db57271
commit
ac90ca829f
29
app.py
29
app.py
@ -1,4 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
This is the top level module, containing the main application. Launching this file will launch the scheduler part of the consumer application.
|
||||||
|
"""
|
||||||
import sentry_sdk
|
import sentry_sdk
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
@ -8,10 +11,6 @@ from redis_super_storage import RedisSuperStorage
|
|||||||
from communicators import ConsumerCommunicator, ProducerCommunicator
|
from communicators import ConsumerCommunicator, ProducerCommunicator
|
||||||
from ip_watchdog import IPWatchdog
|
from ip_watchdog import IPWatchdog
|
||||||
|
|
||||||
"""
|
|
||||||
Scheduler
|
|
||||||
"""
|
|
||||||
|
|
||||||
__author__ = "@kocsisr"
|
__author__ = "@kocsisr"
|
||||||
__copyright__ = "Copyright 2020, GoldenPogácsa Team"
|
__copyright__ = "Copyright 2020, GoldenPogácsa Team"
|
||||||
__module_name__ = "app"
|
__module_name__ = "app"
|
||||||
@ -20,13 +19,33 @@ __version__text__ = "1"
|
|||||||
sentry_sdk.init("https://0a106e104e114bc9a3fa47f9cb0db2f4@sentry.kmlabz.com/10")
|
sentry_sdk.init("https://0a106e104e114bc9a3fa47f9cb0db2f4@sentry.kmlabz.com/10")
|
||||||
|
|
||||||
|
|
||||||
def get_initial_ip_list():
|
def get_initial_ip_list() -> list:
|
||||||
|
"""
|
||||||
|
This method is used to parse the content of INITIAL_SERVERS environment variable.
|
||||||
|
The contents of this variable is a list of ip addresses separated by commas.
|
||||||
|
This mehod returns a Python native `list` object containing the addreseses provided.
|
||||||
|
|
||||||
|
:return: A list of ip addresses provided by the environmental variable
|
||||||
|
"""
|
||||||
ip_list = os.environ['INITIAL_SERVERS'].split(',')
|
ip_list = os.environ['INITIAL_SERVERS'].split(',')
|
||||||
logging.debug('Initial ip list ' + ", ".join(ip_list))
|
logging.debug('Initial ip list ' + ", ".join(ip_list))
|
||||||
return ip_list
|
return ip_list
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
"""
|
||||||
|
This is the main method of the scheduler application.
|
||||||
|
|
||||||
|
This method does basically the followings:
|
||||||
|
* Sets up logging
|
||||||
|
* Creates the RedisSuperStorage object (connecting to Redis database)
|
||||||
|
* Sets up communicators and IP watchdog
|
||||||
|
* Performs an initial synchronization to all other consumers.
|
||||||
|
* Starts the main loop which does roughly the following:
|
||||||
|
* Syncrhronizes with all other consumers
|
||||||
|
* Check if ip address changed. If yes, then push updates to all producers.
|
||||||
|
* Wait `RUN_INTERVAL` seconds (provided by envvar)
|
||||||
|
"""
|
||||||
# set logging preferences
|
# set logging preferences
|
||||||
logging.basicConfig(filename='', level=logging.DEBUG)
|
logging.basicConfig(filename='', level=logging.DEBUG)
|
||||||
|
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
This module contains the classes used for communicating with other consumers as well as the producers themselves.
|
||||||
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
import requests
|
import requests
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
This module contains the IPWatchdog class which is responsible for detecting ip address changes on the host machine.
|
||||||
|
"""
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
import logging
|
import logging
|
||||||
import socket
|
import socket
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
This module contains the RedisSuperStorage module which is responsible to store and load the data structure used by the constumer.
|
||||||
|
"""
|
||||||
import redis
|
import redis
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
Reference in New Issue
Block a user