Execution timestamp is now generated before thread creation, not inside the thread. Some cleanups and fixes.

This commit is contained in:
Johannes Findeisen 2022-09-10 03:01:29 +02:00
commit 62c1568b4d
4 changed files with 28 additions and 24 deletions

View file

@ -20,10 +20,12 @@
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
# OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# TODO: CHECK ALL ERROR HANDLING!!! """
# TODO: Refactor all logging and make it clean and consistent. TODO: CHECK ALL ERROR HANDLING!!!
# TODO: become more verbose in each log level and log only to error when it really TODO: Refactor all logging and make it clean and consistent.
# is an error else log to info and even add debug messages in DEBUG level. TODO: become more verbose in each log level and log only to error when it really
is an error else log to info and even add debug messages in DEBUG level.
"""
import argparse import argparse
import calendar import calendar
@ -49,7 +51,7 @@ MINOR changes are "just-in-time" changes or small enhancements which should not
documentation. documentation.
FIXES should never affect anything else then stability or security. FIXES should never affect anything else then stability or security.
""" """
__version__ = '0.9.0.1' __version__ = '0.9.1.1'
__author__ = 'Johannes Findeisen <you@hanez.org>' __author__ = 'Johannes Findeisen <you@hanez.org>'
logger = logging.getLogger('uplink') logger = logging.getLogger('uplink')
@ -192,8 +194,9 @@ def main():
ste.start() ste.start()
while True: while True:
timestamp = calendar.timegm(time.gmtime())
for i in range(len(configuration.get_uplinks())): for i in range(len(configuration.get_uplinks())):
ft = Thread(target=u.fetch_data, daemon=True, args=(i,)) ft = Thread(target=u.fetch_data, daemon=True, args=(i, timestamp,))
ft.start() ft.start()
try: try:
time.sleep(configuration.get_interval()) time.sleep(configuration.get_interval())

View file

@ -18,9 +18,6 @@
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
# OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import re
import socket
from logging import getLogger from logging import getLogger
logger = getLogger('uplink') logger = getLogger('uplink')

View file

@ -18,8 +18,10 @@
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
# OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# TODO: Select a template engine for easy output creation. Mako preferred but need to """
# take a look at Jinja. TODO: Select a template engine for easy output creation. Mako preferred but need to
take a look at Jinja.
"""
import cherrypy import cherrypy
import json import json

View file

@ -18,9 +18,11 @@
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
# OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# TODO: Make the use of a database optional and only output to stdout and/or in a logfile (use rich """
# for colorizing the std output (https://github.com/Textualize/rich)); Output to a CSV file should TODO: Make the use of a database optional and only output to stdout and/or in a logfile (use rich
# be optional too. Also reinvent SQLite as database backend. for colorizing the std output (https://github.com/Textualize/rich)); Output to a CSV file should
be optional too. Also reinvent SQLite as database backend.
"""
import calendar import calendar
import socket import socket
@ -43,8 +45,7 @@ class Uplink(Daemon):
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
def fetch_data(self, i): def fetch_data(self, i, timestamp):
timestamp = calendar.timegm(time.gmtime())
local_time = time.localtime(timestamp) local_time = time.localtime(timestamp)
date_formatted = time.strftime('%Y-%m-%d', local_time) date_formatted = time.strftime('%Y-%m-%d', local_time)
time_formatted = time.strftime('%H:%M:%S', local_time) time_formatted = time.strftime('%H:%M:%S', local_time)
@ -172,7 +173,8 @@ class Uplink(Daemon):
stt.start() stt.start()
while True: while True:
timestamp = calendar.timegm(time.gmtime())
for i in range(len(self.__configuration.get_uplinks())): for i in range(len(self.__configuration.get_uplinks())):
ut = Thread(target=self.fetch_data, daemon=True, args=(i,)) ut = Thread(target=self.fetch_data, daemon=True, args=(i, timestamp,))
ut.start() ut.start()
time.sleep(self.__configuration.get_interval()) time.sleep(self.__configuration.get_interval())