From 205ec17375146c5923de0fd26f1abbd33b384d4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Chac=C3=B3n?= Date: Sat, 4 Feb 2023 11:27:28 -0700 Subject: [PATCH] Use advanced scheduler by default --- src/scheduler.py | 50 +++++++++++++++++++----------------------------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/src/scheduler.py b/src/scheduler.py index f9b74df2..c1235812 100644 --- a/src/scheduler.py +++ b/src/scheduler.py @@ -7,6 +7,9 @@ if automaticImportUISP: from integrationUISP import importFromUISP if automaticImportSplynx: from integrationSplynx import importFromSplynx +from apscheduler.schedulers.background import BlockingScheduler + +ads = BlockingScheduler() def importFromCRM(): if automaticImportUISP: @@ -20,6 +23,16 @@ def importFromCRM(): except: print("Failed to import from Splynx") +def graphHandler(): + try: + refreshBandwidthGraphs() + except: + print("Failed to update bandwidth graphs") + try: + refreshLatencyGraphs() + except: + print("Failed to update latency graphs") + def importAndShapeFullReload(): importFromCRM() refreshShapers() @@ -28,35 +41,12 @@ def importAndShapePartialReload(): importFromCRM() refreshShapersUpdateOnly() -def graph(): - time.sleep(10) - try: - refreshBandwidthGraphs() - except: - print("Failed to run refreshBandwidthGraphs()") - time.sleep(10) - try: - refreshBandwidthGraphs() - except: - print("Failed to run refreshBandwidthGraphs()") - time.sleep(10) - try: - refreshBandwidthGraphs() - except: - print("Failed to run refreshBandwidthGraphs()") - time.sleep(1) - try: - refreshLatencyGraphs() - except: - print("Failed to run refreshLatencyGraphs()") - if __name__ == '__main__': importAndShapeFullReload() - while True: - finish_time = datetime.datetime.now() + datetime.timedelta(minutes=30) - while datetime.datetime.now() < finish_time: - if influxDBEnabled: - graph() - else: - time.sleep(1) - importAndShapePartialReload() + + ads.add_job(importAndShapePartialReload, 'interval', minutes=30) + + if influxDBEnabled: + ads.add_job(graphHandler, 'interval', seconds=10) + + ads.start()