Skip to content

Commit

Permalink
Update routine_tasks.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sondregronas authored Jul 14, 2024
1 parent cbdc875 commit 4474977
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions BookingSystem/routine_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from teams import send_report
from user import prune_inactive

from functools import partial


def run_continuously(interval=1):
cease_continuous_run = threading.Event()
Expand Down Expand Up @@ -39,17 +41,26 @@ def _routine_backup():


def start_routine():
def _task(job_func):
try:
job_func()
except Exception as e:
logger.error(e)

def run_mon_to_fri_at_time(job_func, at_time):
schedule.every().monday.at(at_time).do(job_func)
schedule.every().tuesday.at(at_time).do(job_func)
schedule.every().wednesday.at(at_time).do(job_func)
schedule.every().thursday.at(at_time).do(job_func)
schedule.every().friday.at(at_time).do(job_func)

_send_report = partial(_task(send_report))
_prune_inactive = partial(_task(prune_inactive))

# TODO: Add a setting to change the time of the day these run
run_mon_to_fri_at_time(send_report, "10:00")
run_mon_to_fri_at_time(_send_report, "10:00")
logger.info("Scheduled send_report to run Mon-Fri at 10:00")
schedule.every().sunday.at("01:00").do(prune_inactive)
schedule.every().sunday.at("01:00").do(_prune_inactive)
logger.info("Scheduled prune_inactive to run on Sundays at 01:00")
schedule.every().sunday.at("01:05").do(_routine_backup)
logger.info("Scheduled _routine_backup to run on Sundays at 01:05")
Expand Down

0 comments on commit 4474977

Please sign in to comment.