set up initial classes
This commit is contained in:
0
alert-scheduler/__init__.py
Normal file
0
alert-scheduler/__init__.py
Normal file
@@ -5,43 +5,26 @@
|
|||||||
{
|
{
|
||||||
"jobName": "Print schedule",
|
"jobName": "Print schedule",
|
||||||
"jobType": "cyclic",
|
"jobType": "cyclic",
|
||||||
"jobFunction": "printScheduler",
|
"jobFunction": "output_schedule",
|
||||||
"dtTimeDelta": {
|
"dtTimeDelta": {
|
||||||
"minutes": 15
|
"minutes": 15
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"jobName": "Example to show all possible scheduling options...",
|
"jobName": "Output Alerts",
|
||||||
"jobType": "once",
|
"jobType": "cyclic",
|
||||||
"jobFunction": "foo",
|
"jobFunction": "output_alerts",
|
||||||
"dtTime": {
|
|
||||||
"_comment": "for minutely,hourly,daily,weekly & once jobs....",
|
|
||||||
"second": 0,
|
|
||||||
"minute": 0,
|
|
||||||
"hour": 0,
|
|
||||||
"dayOfWeek": [
|
|
||||||
"Monday",
|
|
||||||
"Tuesday",
|
|
||||||
"Wednesday",
|
|
||||||
"Thursday",
|
|
||||||
"Friday",
|
|
||||||
"Saturday",
|
|
||||||
"Sunday"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"dtTimeDelta": {
|
"dtTimeDelta": {
|
||||||
"_comment": "for cyclic & once jobs, in x minutes....",
|
"seconds": 5
|
||||||
"minutes": 0
|
}
|
||||||
},
|
},
|
||||||
"dtDateTime": {
|
{
|
||||||
"_comment": "for once jobs, at point in time....",
|
"jobName": "Update Alerts",
|
||||||
"year": 2022,
|
"jobType": "cyclic",
|
||||||
"month": 1,
|
"jobFunction": "update_alerts",
|
||||||
"day": 1,
|
"dtTimeDelta": {
|
||||||
"hour": 0,
|
"minutes": 1
|
||||||
"minute": 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
0
alert-scheduler/src/__init__.py
Normal file
0
alert-scheduler/src/__init__.py
Normal file
BIN
alert-scheduler/src/__pycache__/globals.cpython-310.pyc
Normal file
BIN
alert-scheduler/src/__pycache__/globals.cpython-310.pyc
Normal file
Binary file not shown.
BIN
alert-scheduler/src/__pycache__/output_alerts.cpython-310.pyc
Normal file
BIN
alert-scheduler/src/__pycache__/output_alerts.cpython-310.pyc
Normal file
Binary file not shown.
BIN
alert-scheduler/src/__pycache__/update_alerts.cpython-310.pyc
Normal file
BIN
alert-scheduler/src/__pycache__/update_alerts.cpython-310.pyc
Normal file
Binary file not shown.
1
alert-scheduler/src/globals.py
Normal file
1
alert-scheduler/src/globals.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
alerts = []
|
||||||
18
alert-scheduler/src/output_alerts.py
Normal file
18
alert-scheduler/src/output_alerts.py
Normal file
@@ -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()
|
||||||
|
|
||||||
14
alert-scheduler/src/update_alerts.py
Normal file
14
alert-scheduler/src/update_alerts.py
Normal file
@@ -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()
|
||||||
@@ -5,11 +5,23 @@ import json
|
|||||||
import os.path
|
import os.path
|
||||||
import time
|
import time
|
||||||
|
|
||||||
def foo():
|
from output_alerts import outputAlerts
|
||||||
# print("\nJust chilling...\n")
|
from update_alerts import updateAlerts
|
||||||
return
|
|
||||||
|
|
||||||
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()
|
date = dt.datetime.now()
|
||||||
print(str(date)+": The currently available jobs are:\n")
|
print(str(date)+": The currently available jobs are:\n")
|
||||||
print(schedule)
|
print(schedule)
|
||||||
@@ -26,15 +38,18 @@ def addParameter(name, object, dict):
|
|||||||
|
|
||||||
def addDtTimeDeltaJob(job, schedule: Scheduler, function, once):
|
def addDtTimeDeltaJob(job, schedule: Scheduler, function, once):
|
||||||
dtTimeDelta = job['dtTimeDelta']
|
dtTimeDelta = job['dtTimeDelta']
|
||||||
if 'minutes' in dtTimeDelta:
|
if 'minutes' or 'seconds' in dtTimeDelta:
|
||||||
parameters = {}
|
parameters = {}
|
||||||
addParameter('minutes', dtTimeDelta, parameters)
|
if 'minutes' in dtTimeDelta:
|
||||||
|
addParameter('minutes', dtTimeDelta, parameters)
|
||||||
|
if 'seconds' in dtTimeDelta:
|
||||||
|
addParameter('seconds', dtTimeDelta, parameters)
|
||||||
if once:
|
if once:
|
||||||
schedule.once(dt.timedelta(**parameters), function)
|
schedule.once(dt.timedelta(**parameters), function)
|
||||||
else:
|
else:
|
||||||
schedule.cyclic(dt.timedelta(**parameters), function)
|
schedule.cyclic(dt.timedelta(**parameters), function)
|
||||||
else:
|
else:
|
||||||
print("ERROR: missing minutes in job: ", job['jobName'])
|
print("ERROR: missing time delta in job: ", job['jobName'])
|
||||||
return
|
return
|
||||||
|
|
||||||
def scheduleDayOfWeek(day, daylist, schedule, function, parameters, once):
|
def scheduleDayOfWeek(day, daylist, schedule, function, parameters, once):
|
||||||
@@ -168,7 +183,6 @@ def addJobs(schedule: Scheduler):
|
|||||||
# schedule = Scheduler(n_threads=0)
|
# schedule = Scheduler(n_threads=0)
|
||||||
schedule = Scheduler()
|
schedule = Scheduler()
|
||||||
addJobs(schedule)
|
addJobs(schedule)
|
||||||
printScheduler()
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
start_time = time.perf_counter()
|
start_time = time.perf_counter()
|
||||||
|
|||||||
Reference in New Issue
Block a user