-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduler.py
28 lines (25 loc) · 876 Bytes
/
scheduler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Dev Dominic Minnich 2024
# scheduler.py
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.triggers.interval import IntervalTrigger
import atexit
import subprocess
def backup_database():
try:
# Call the backup script
subprocess.run(['python', 'backup_db.py'], check=True)
print('Database backup completed successfully!')
except subprocess.CalledProcessError as e:
print(f'An error occurred during the backup: {e}')
def start_scheduler():
scheduler = BackgroundScheduler()
scheduler.start()
scheduler.add_job(
func=backup_database,
trigger=IntervalTrigger(days=3),
id='database_backup_job',
name='Database Backup Job',
replace_existing=True
)
# Shut down the scheduler when exiting the app
atexit.register(lambda: scheduler.shutdown())