Skip to content

Commit

Permalink
Add optional function for using apscheduler instead of schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
nikilase committed Mar 18, 2024
1 parent b215ea3 commit 876687d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
37 changes: 24 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
import sys
import threading
import time

import schedule
import time
from apscheduler.schedulers.blocking import BlockingScheduler

from jobs.kostal_stats_job import main as k_m
from jobs.kostal_aggregate_job import main as a_m
from jobs.kostal_stats_job import main as k_m


def main():
schedule.every(10).seconds.do(k_m)
schedule.every(5).minutes.do(a_m)
schedule.every(10).seconds.do(k_m)
schedule.every(5).minutes.do(a_m)

try:
while True:
schedule.run_pending()
time.sleep(0.5)
except KeyboardInterrupt:
print("Shutting down from Keyboard Interrupt!")
sys.exit()


try:
while True:
schedule.run_pending()
time.sleep(0.5)
except KeyboardInterrupt:
print("Shutting down from Keyboard Interrupt!")
sys.exit()
def main_apscheduler():
try:
scheduler = BlockingScheduler()
scheduler.add_job(k_m, "cron", second="0/10")
scheduler.add_job(a_m, "cron", minute="0/5")
scheduler.start()
except KeyboardInterrupt:
print("Shutting down from Keyboard Interrupt!")
sys.exit()


if __name__ == "__main__":
main()
main()
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
requests~=2.31.0
influxdb~=5.3.1
schedule~=1.2.1
pycryptodomex~=3.20.0
pycryptodomex~=3.20.0
APScheduler~=3.10.4

0 comments on commit 876687d

Please sign in to comment.