2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-02-19 13:18:03 +00:00

[setup] invoke command updates (#11340)

* invoke command updates

- wait for db before migrating data
- improve task state reporting
- early return from isGeneratingSchema

* Disable warning message (for now)

* Fix typo

- This caused large delay when restoring data

* Remove debug statement

* Add warning message if isGeneratingSchema called falls through unexpectedly
This commit is contained in:
Oliver
2026-02-17 00:22:35 +11:00
committed by GitHub
parent 5f4dd49b12
commit 430dfbbae5
3 changed files with 55 additions and 28 deletions

View File

@@ -84,10 +84,11 @@ class InvenTreeMaintenanceModeBackend(AbstractStateBackend):
r -= 1
if r == 0:
logger.warning(
'Failed to set maintenance mode state after %s retries', retries
)
# Disable this warning message (for now) as it is confusing users with no upside
# if r == 0:
# logger.warning(
# 'Failed to set maintenance mode state after %s retries', retries
# )
class InvenTreeMailLoggingBackend(BaseEmailBackend):

View File

@@ -6,6 +6,11 @@ import os
import sys
import warnings
import structlog
logger = structlog.get_logger('inventree')
# Keep track of loaded apps, to prevent multiple executions of ready functions
_loaded_apps = set()
@@ -33,6 +38,11 @@ def isInTestMode():
return 'test' in sys.argv or sys.argv[0].endswith('pytest')
def isWaitingForDatabase():
"""Return True if we are currently waiting for the database to be ready."""
return 'wait_for_db' in sys.argv
def isImportingData():
"""Returns True if the database is currently importing (or exporting) data, e.g. 'loaddata' command is performed."""
return any(x in sys.argv for x in ['flush', 'loaddata', 'dumpdata'])
@@ -61,7 +71,7 @@ def isRunningBackup():
'backup',
'restore',
'dbbackup',
'dbresotore',
'dbrestore',
'mediabackup',
'mediarestore',
]
@@ -82,11 +92,23 @@ def isGeneratingSchema():
if isInTestMode():
return False
if isWaitingForDatabase():
return False
if 'schema' in sys.argv:
return True
# This is a very inefficient call - so we only use it as a last resort
return any('drf_spectacular' in frame.filename for frame in inspect.stack())
result = any('drf_spectacular' in frame.filename for frame in inspect.stack())
if not result:
# We should only get here if we *are* generating schema
# Any other time this is called, it should be from a server thread, worker thread, or test mode
logger.warning(
'isGeneratingSchema called outside of expected contexts - this may be a sign of a problem with the ready() function'
)
return result
def isInWorkerThread():