Merge pull request #248 from LibreQoE/fixScheduler

Fix scheduler
This commit is contained in:
Robert Chacón 2023-02-04 11:29:18 -07:00 committed by GitHub
commit eed68c6474
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 97 deletions

View File

@ -10,3 +10,4 @@ requests
schedule schedule
waitress waitress
setuptools >= 65.5.1 setuptools >= 65.5.1
apscheduler

View File

@ -7,6 +7,9 @@ if automaticImportUISP:
from integrationUISP import importFromUISP from integrationUISP import importFromUISP
if automaticImportSplynx: if automaticImportSplynx:
from integrationSplynx import importFromSplynx from integrationSplynx import importFromSplynx
from apscheduler.schedulers.background import BlockingScheduler
ads = BlockingScheduler()
def importFromCRM(): def importFromCRM():
if automaticImportUISP: if automaticImportUISP:
@ -20,6 +23,16 @@ def importFromCRM():
except: except:
print("Failed to import from Splynx") 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(): def importAndShapeFullReload():
importFromCRM() importFromCRM()
refreshShapers() refreshShapers()
@ -28,35 +41,12 @@ def importAndShapePartialReload():
importFromCRM() importFromCRM()
refreshShapersUpdateOnly() 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__': if __name__ == '__main__':
importAndShapeFullReload() importAndShapeFullReload()
while True:
finish_time = datetime.datetime.now() + datetime.timedelta(minutes=30) ads.add_job(importAndShapePartialReload, 'interval', minutes=30)
while datetime.datetime.now() < finish_time:
if influxDBEnabled: if influxDBEnabled:
graph() ads.add_job(graphHandler, 'interval', seconds=10)
else:
time.sleep(1) ads.start()
importAndShapePartialReload()

View File

@ -1,67 +0,0 @@
import time
from LibreQoS import refreshShapers, refreshShapersUpdateOnly
from graphInfluxDB import refreshBandwidthGraphs, refreshLatencyGraphs
from ispConfig import influxDBEnabled, automaticImportUISP, automaticImportSplynx, httpRestIntegrationConfig
if automaticImportUISP:
from integrationUISP import importFromUISP
if automaticImportSplynx:
from integrationSplynx import importFromSplynx
if httpRestIntegrationConfig['enabled']:
from integrationRestHttp import importFromRestHttp
from apscheduler.schedulers.background import BlockingScheduler
ads = BlockingScheduler()
def importFromCRM():
if automaticImportUISP:
try:
importFromUISP()
except:
print("Failed to import from UISP")
elif automaticImportSplynx:
try:
importFromSplynx()
except:
print("Failed to import from Splynx")
elif httpRestIntegrationConfig['enabled']:
try:
importFromRestHttp()
except:
print("Failed to import from RestHttp")
def importAndShapeFullReload():
importFromCRM()
refreshShapers()
def importAndShapePartialReload():
importFromCRM()
refreshShapersUpdateOnly()
if __name__ == '__main__':
importAndShapeFullReload()
# schedule.every().day.at("04:00").do(importAndShapeFullReload)
ads.add_job(importAndShapeFullReload, 'cron', hour=4)
# schedule.every(30).minutes.do(importAndShapePartialReload)
ads.add_job(importAndShapePartialReload, 'interval', minutes=30)
if influxDBEnabled:
# schedule.every(10).seconds.do(refreshBandwidthGraphs)
ads.add_job(refreshBandwidthGraphs, 'interval', seconds=10)
# schedule.every(30).seconds.do(refreshLatencyGraphs)
# Commented out until refreshLatencyGraphs works in v.14
# ads.add_job(refreshLatencyGraphs, 'interval', seconds=30)
# while True:
# schedule.run_pending()
# time.sleep(1)
ads.start()