Skip to content
This repository was archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
feat: created scheduler to run data backup job when starting web server
Browse files Browse the repository at this point in the history
  • Loading branch information
lc_hd committed Oct 24, 2023
1 parent 4ae168d commit 6138d2a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from django.core import management
from django.core.management.base import BaseCommand

from apscheduler.schedulers.background import BlockingScheduler

from dbbackup.storage import Storage
from dbbackup.management.commands import dbbackup

Expand Down Expand Up @@ -88,7 +90,7 @@ def remove_oldest_file(self, interval: Interval, files_in_folder):
self.style.SUCCESS(f'Error Deleting File {oldest_file}')
)

def handle(self, *args, **options):
def job(self):
self.stdout.write(
self.style.SUCCESS('Running backup Script')
)
Expand All @@ -109,3 +111,8 @@ def handle(self, *args, **options):
self.stdout.write(
self.style.SUCCESS('Backup Script Complete')
)

def handle(self, *args, **options):
scheduler = BlockingScheduler()
scheduler.add_job(self.job, 'cron', hour=23, minute=30)
scheduler.start()
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
#

. ./env.sh
python manage.py backupfiles &
python manage.py run_data_backup &
gunicorn -b :$PORT -w 2 --timeout 90 localcontexts.wsgi:application

0 comments on commit 6138d2a

Please sign in to comment.