From 6ef8fee79a629418c6166c002ddecba6654a33b2 Mon Sep 17 00:00:00 2001 From: nils Date: Sun, 25 Feb 2024 11:18:37 +0100 Subject: [PATCH] set up initial classes --- alert-scheduler/__init__.py | 0 alert-scheduler/config/runCfg.json | 43 ++++++------------ alert-scheduler/src/__init__.py | 0 .../src/__pycache__/globals.cpython-310.pyc | Bin 0 -> 160 bytes .../__pycache__/output_alerts.cpython-310.pyc | Bin 0 -> 831 bytes .../__pycache__/update_alerts.cpython-310.pyc | Bin 0 -> 783 bytes alert-scheduler/src/globals.py | 1 + alert-scheduler/src/output_alerts.py | 18 ++++++++ alert-scheduler/src/update_alerts.py | 14 ++++++ alert-scheduler/src/watchdog.py | 30 ++++++++---- 10 files changed, 68 insertions(+), 38 deletions(-) create mode 100644 alert-scheduler/__init__.py create mode 100644 alert-scheduler/src/__init__.py create mode 100644 alert-scheduler/src/__pycache__/globals.cpython-310.pyc create mode 100644 alert-scheduler/src/__pycache__/output_alerts.cpython-310.pyc create mode 100644 alert-scheduler/src/__pycache__/update_alerts.cpython-310.pyc create mode 100644 alert-scheduler/src/globals.py create mode 100644 alert-scheduler/src/output_alerts.py create mode 100644 alert-scheduler/src/update_alerts.py diff --git a/alert-scheduler/__init__.py b/alert-scheduler/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/alert-scheduler/config/runCfg.json b/alert-scheduler/config/runCfg.json index af3f339..d8fcab4 100644 --- a/alert-scheduler/config/runCfg.json +++ b/alert-scheduler/config/runCfg.json @@ -5,43 +5,26 @@ { "jobName": "Print schedule", "jobType": "cyclic", - "jobFunction": "printScheduler", + "jobFunction": "output_schedule", "dtTimeDelta": { "minutes": 15 } }, { - "jobName": "Example to show all possible scheduling options...", - "jobType": "once", - "jobFunction": "foo", - "dtTime": { - "_comment": "for minutely,hourly,daily,weekly & once jobs....", - "second": 0, - "minute": 0, - "hour": 0, - "dayOfWeek": [ - "Monday", - "Tuesday", - "Wednesday", - "Thursday", - "Friday", - "Saturday", - "Sunday" - ] - }, + "jobName": "Output Alerts", + "jobType": "cyclic", + "jobFunction": "output_alerts", "dtTimeDelta": { - "_comment": "for cyclic & once jobs, in x minutes....", - "minutes": 0 - }, - "dtDateTime": { - "_comment": "for once jobs, at point in time....", - "year": 2022, - "month": 1, - "day": 1, - "hour": 0, - "minute": 0 + "seconds": 5 + } + }, + { + "jobName": "Update Alerts", + "jobType": "cyclic", + "jobFunction": "update_alerts", + "dtTimeDelta": { + "minutes": 1 } - } ] } diff --git a/alert-scheduler/src/__init__.py b/alert-scheduler/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/alert-scheduler/src/__pycache__/globals.cpython-310.pyc b/alert-scheduler/src/__pycache__/globals.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7f46dda2ce103847784e826f1d3100dedb45c237 GIT binary patch literal 160 zcmd1j<>g`kf}KLQQ@MfkV-N=!FakLaKwQiLB+?n87*ZI588jLFG#PKPCFZ0Sl@zaJ zC}IN2fr(#M`WgATsrq@DImP-Zsb#4-`33sri6zMyDf#L8VD-Ai$r-6Br9iFv#YM^b e={fmHi8;l31(mlrY;yBK5_TXvi$P{`FaQ8AL?{!7VyaUBm zZ~zs2JI)Sb5R71fOU@0qtH55X{N~qaE6f+g7`2mVh zMd}Q{a}^-?!X@p{cSHZiV;dw3E;PCyOp{j>-7WGt+FLYxftzBtAmJ9ivG2fe2t?z# z2S~YFc&>8WD1Ge~a;tgb&E!JHw;pQ~)s?sV2{Ynv(kS=ViseJT5DquO=m zOJ3S)qt$@?GHa@Ar27wT)!n#AVw-I*CE;0tTgVc&e>R#G5 znd8Ce5wM{Lb#Z65O)ndL-7hh=B#2=9=l6R3&w0@8B;Yv~_Fg&?k@}hhk5X-Ixg+YyrT9|LmHtC7xYdItY?3A^Bb E0g3Xgm;e9( literal 0 HcmV?d00001 diff --git a/alert-scheduler/src/__pycache__/update_alerts.cpython-310.pyc b/alert-scheduler/src/__pycache__/update_alerts.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e1e66a3a24af841c120b3bc458d586d3c9e42608 GIT binary patch literal 783 zcmZvav2NQi5QdKwEh~=fp+SL8-BqB`3lu?u4&A(D(?TdZ);1tpE-9z5(Jg+Ec=RhV zW2O#yflRrR8dpI~fZ~xn{{P3Ls^M?|)Xdp~d7|-=C*2m%z{Ct^CtGP)Rv(lw#ZcSM&)8BbrOtG4z&5^IJm>OIWLh5XhwnYEb&X;Q+ zX+2xaYOVWBz$mfUeC&dszh=AxXZQwOQNX~qM?phoS+0#3)be}zu$ASwaZ+M)_Qt85 zyz@B}XhbJ#xEDJrlm73RNXsc+71eTm%-M#tJ$$ttiOr`sww(f#6kleX^tm#Nd~US% z1Fh#3*O1~^>tCz9Yn9anP)flfd^UWp$I6 Xt`+3WV=_Ma)^c2M None: + self.alert_index = 0 + self._get_alerts() + + def print_next(self): + pass + + def _get_alerts(self): + self.alerts = alerts.copy() + diff --git a/alert-scheduler/src/update_alerts.py b/alert-scheduler/src/update_alerts.py new file mode 100644 index 0000000..bf29ca7 --- /dev/null +++ b/alert-scheduler/src/update_alerts.py @@ -0,0 +1,14 @@ +from globals import alerts + +class updateAlerts: + + alerts = [] + + def __init__(self) -> None: + self._get_alerts() + + def update(self): + pass + + def _get_alerts(self): + self.alerts = alerts.copy() diff --git a/alert-scheduler/src/watchdog.py b/alert-scheduler/src/watchdog.py index 07d4b59..0fd6444 100644 --- a/alert-scheduler/src/watchdog.py +++ b/alert-scheduler/src/watchdog.py @@ -5,11 +5,23 @@ import json import os.path import time -def foo(): - # print("\nJust chilling...\n") - return +from output_alerts import outputAlerts +from update_alerts import updateAlerts -def printScheduler(): +printer = outputAlerts() +updater = updateAlerts() + +def output_alerts(): + print("Output-Alerts...") + printer.print_next() + pass + +def update_alerts(): + print("Update-Alerts...") + updater.update() + pass + +def output_schedule(): date = dt.datetime.now() print(str(date)+": The currently available jobs are:\n") print(schedule) @@ -26,15 +38,18 @@ def addParameter(name, object, dict): def addDtTimeDeltaJob(job, schedule: Scheduler, function, once): dtTimeDelta = job['dtTimeDelta'] - if 'minutes' in dtTimeDelta: + if 'minutes' or 'seconds' in dtTimeDelta: parameters = {} - addParameter('minutes', dtTimeDelta, parameters) + if 'minutes' in dtTimeDelta: + addParameter('minutes', dtTimeDelta, parameters) + if 'seconds' in dtTimeDelta: + addParameter('seconds', dtTimeDelta, parameters) if once: schedule.once(dt.timedelta(**parameters), function) else: schedule.cyclic(dt.timedelta(**parameters), function) else: - print("ERROR: missing minutes in job: ", job['jobName']) + print("ERROR: missing time delta in job: ", job['jobName']) return def scheduleDayOfWeek(day, daylist, schedule, function, parameters, once): @@ -168,7 +183,6 @@ def addJobs(schedule: Scheduler): # schedule = Scheduler(n_threads=0) schedule = Scheduler() addJobs(schedule) -printScheduler() while True: start_time = time.perf_counter()