mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 13:15:43 +00:00 
			
		
		
		
	try/catch for operational error
- Database might not yet be ready to load models
This commit is contained in:
		| @@ -135,6 +135,7 @@ class ScheduleMixin: | |||||||
|         Register the tasks with the database |         Register the tasks with the database | ||||||
|         """ |         """ | ||||||
|  |  | ||||||
|  |         try: | ||||||
|             from django_q.models import Schedule |             from django_q.models import Schedule | ||||||
|  |  | ||||||
|             for key, task in self.scheduled_tasks.items(): |             for key, task in self.scheduled_tasks.items(): | ||||||
| @@ -153,12 +154,16 @@ class ScheduleMixin: | |||||||
|                         minutes=task.get('minutes', None), |                         minutes=task.get('minutes', None), | ||||||
|                         repeats=task.get('repeats', -1), |                         repeats=task.get('repeats', -1), | ||||||
|                     ) |                     ) | ||||||
|  |         except OperationalError: | ||||||
|  |             # Database might not yet be ready | ||||||
|  |             pass | ||||||
|  |  | ||||||
|     def unregister_tasks(self): |     def unregister_tasks(self): | ||||||
|         """ |         """ | ||||||
|         Deregister the tasks with the database |         Deregister the tasks with the database | ||||||
|         """ |         """ | ||||||
|  |  | ||||||
|  |         try: | ||||||
|             from django_q.models import Schedule |             from django_q.models import Schedule | ||||||
|  |  | ||||||
|             for key, task in self.scheduled_tasks.items(): |             for key, task in self.scheduled_tasks.items(): | ||||||
| @@ -170,6 +175,9 @@ class ScheduleMixin: | |||||||
|                     scheduled_task.delete() |                     scheduled_task.delete() | ||||||
|                 except Schedule.DoesNotExist: |                 except Schedule.DoesNotExist: | ||||||
|                     pass |                     pass | ||||||
|  |         except OperationalError: | ||||||
|  |             # Database might not yet be ready | ||||||
|  |             pass | ||||||
|  |  | ||||||
|  |  | ||||||
| class UrlsMixin: | class UrlsMixin: | ||||||
|   | |||||||
| @@ -301,7 +301,6 @@ class PluginsRegistry: | |||||||
|         logger.info('Activating plugin tasks') |         logger.info('Activating plugin tasks') | ||||||
|  |  | ||||||
|         from common.models import InvenTreeSetting |         from common.models import InvenTreeSetting | ||||||
|         from django_q.models import Schedule |  | ||||||
|  |  | ||||||
|         # List of tasks we have activated |         # List of tasks we have activated | ||||||
|         task_keys = [] |         task_keys = [] | ||||||
| @@ -323,6 +322,9 @@ class PluginsRegistry: | |||||||
|  |  | ||||||
|         # Remove any scheduled tasks which do not match |         # Remove any scheduled tasks which do not match | ||||||
|         # This stops 'old' plugin tasks from accumulating |         # This stops 'old' plugin tasks from accumulating | ||||||
|  |         try: | ||||||
|  |             from django_q.models import Schedule | ||||||
|  |  | ||||||
|             scheduled_plugin_tasks = Schedule.objects.filter(name__istartswith="plugin.") |             scheduled_plugin_tasks = Schedule.objects.filter(name__istartswith="plugin.") | ||||||
|  |  | ||||||
|             deleted_count = 0 |             deleted_count = 0 | ||||||
| @@ -334,6 +336,9 @@ class PluginsRegistry: | |||||||
|  |  | ||||||
|             if deleted_count > 0: |             if deleted_count > 0: | ||||||
|                 logger.info(f"Removed {deleted_count} old scheduled tasks") |                 logger.info(f"Removed {deleted_count} old scheduled tasks") | ||||||
|  |         except OperationalError: | ||||||
|  |             # Database might not yet be ready | ||||||
|  |             pass | ||||||
|  |  | ||||||
|     def deactivate_integration_schedule(self): |     def deactivate_integration_schedule(self): | ||||||
|         pass |         pass | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user