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 0000000..7f46dda Binary files /dev/null and b/alert-scheduler/src/__pycache__/globals.cpython-310.pyc differ diff --git a/alert-scheduler/src/__pycache__/output_alerts.cpython-310.pyc b/alert-scheduler/src/__pycache__/output_alerts.cpython-310.pyc new file mode 100644 index 0000000..bd3ab1e Binary files /dev/null and b/alert-scheduler/src/__pycache__/output_alerts.cpython-310.pyc differ 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 0000000..e1e66a3 Binary files /dev/null and b/alert-scheduler/src/__pycache__/update_alerts.cpython-310.pyc differ diff --git a/alert-scheduler/src/globals.py b/alert-scheduler/src/globals.py new file mode 100644 index 0000000..5ab4c56 --- /dev/null +++ b/alert-scheduler/src/globals.py @@ -0,0 +1 @@ +alerts = [] \ No newline at end of file diff --git a/alert-scheduler/src/output_alerts.py b/alert-scheduler/src/output_alerts.py new file mode 100644 index 0000000..25e2a21 --- /dev/null +++ b/alert-scheduler/src/output_alerts.py @@ -0,0 +1,18 @@ + +from globals import alerts + +class outputAlerts: + + alert_index = 0 + alerts = [] + + def __init__(self) -> 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()