try/catch for operational error

- Database might not yet be ready to load models
This commit is contained in:
Oliver Walters 2022-01-07 17:11:53 +11:00
parent c04e07c1fa
commit 103dfaa2a5
2 changed files with 43 additions and 30 deletions

View File

@ -135,6 +135,7 @@ class ScheduleMixin:
Register the tasks with the database
"""
try:
from django_q.models import Schedule
for key, task in self.scheduled_tasks.items():
@ -153,12 +154,16 @@ class ScheduleMixin:
minutes=task.get('minutes', None),
repeats=task.get('repeats', -1),
)
except OperationalError:
# Database might not yet be ready
pass
def unregister_tasks(self):
"""
Deregister the tasks with the database
"""
try:
from django_q.models import Schedule
for key, task in self.scheduled_tasks.items():
@ -170,6 +175,9 @@ class ScheduleMixin:
scheduled_task.delete()
except Schedule.DoesNotExist:
pass
except OperationalError:
# Database might not yet be ready
pass
class UrlsMixin:

View File

@ -301,7 +301,6 @@ class PluginsRegistry:
logger.info('Activating plugin tasks')
from common.models import InvenTreeSetting
from django_q.models import Schedule
# List of tasks we have activated
task_keys = []
@ -323,6 +322,9 @@ class PluginsRegistry:
# Remove any scheduled tasks which do not match
# This stops 'old' plugin tasks from accumulating
try:
from django_q.models import Schedule
scheduled_plugin_tasks = Schedule.objects.filter(name__istartswith="plugin.")
deleted_count = 0
@ -334,6 +336,9 @@ class PluginsRegistry:
if deleted_count > 0:
logger.info(f"Removed {deleted_count} old scheduled tasks")
except OperationalError:
# Database might not yet be ready
pass
def deactivate_integration_schedule(self):
pass