heartwood every commit a ring

Gracefully quit scheduler on keyboard interrupt

b7d08291 by Isaac Bythewood · 3 years ago

modified scheduler/management/commands/scheduler.py
@@ -10,8 +10,10 @@ from ...models import ScheduledTaskclass Command(BaseCommand):    def handle(self, *args, **options):        self.stdout.write('[Scheduler] Starting scheduler...')        while True:            tasks = ScheduledTask.objects.all()            for task in tasks:                if task.should_run():                    now = timezone.now()
@@ -21,5 +23,11 @@ class Command(BaseCommand):                    task.last_run_at = now                    task.next_run_at = task.get_next_run_at(now)                    task.save()            time.sleep(60)            self.stdout.write('[Scheduler] Sleeping scheduler for 60 seconds...')            try:                time.sleep(60)            except KeyboardInterrupt:                self.stdout.write('[Scheduler] Stopping scheduler...')                break