mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 11:36:44 +00:00
Tracing improvements (#6353)
* Prevent tracing in worker thread * Tweak logic * Further improvements * Adds invoke command to launch gunicorn server * Update docstring * Add explicit check for migrations or data import * Update tracing.py Allow tracing in worker thread
This commit is contained in:
parent
282ecebc39
commit
3bfde82394
@ -19,6 +19,25 @@ def isRunningMigrations():
|
|||||||
return any((x in sys.argv for x in ['migrate', 'makemigrations', 'showmigrations']))
|
return any((x in sys.argv for x in ['migrate', 'makemigrations', 'showmigrations']))
|
||||||
|
|
||||||
|
|
||||||
|
def isInWorkerThread():
|
||||||
|
"""Returns True if the current thread is a background worker thread."""
|
||||||
|
return 'qcluster' in sys.argv
|
||||||
|
|
||||||
|
|
||||||
|
def isInServerThread():
|
||||||
|
"""Returns True if the current thread is a server thread."""
|
||||||
|
if isInWorkerThread():
|
||||||
|
return False
|
||||||
|
|
||||||
|
if 'runserver' in sys.argv:
|
||||||
|
return True
|
||||||
|
|
||||||
|
if 'gunicorn' in sys.argv[0]:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def isInMainThread():
|
def isInMainThread():
|
||||||
"""Django runserver starts two processes, one for the actual dev server and the other to reload the application.
|
"""Django runserver starts two processes, one for the actual dev server and the other to reload the application.
|
||||||
|
|
||||||
@ -28,7 +47,7 @@ def isInMainThread():
|
|||||||
if 'runserver' in sys.argv and '--noreload' not in sys.argv:
|
if 'runserver' in sys.argv and '--noreload' not in sys.argv:
|
||||||
return os.environ.get('RUN_MAIN', None) == 'true'
|
return os.environ.get('RUN_MAIN', None) == 'true'
|
||||||
|
|
||||||
return True
|
return not isInWorkerThread()
|
||||||
|
|
||||||
|
|
||||||
def canAppAccessDatabase(
|
def canAppAccessDatabase(
|
||||||
|
@ -19,6 +19,7 @@ from opentelemetry.sdk.metrics.export import (
|
|||||||
from opentelemetry.sdk.trace import TracerProvider
|
from opentelemetry.sdk.trace import TracerProvider
|
||||||
from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter
|
from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter
|
||||||
|
|
||||||
|
import InvenTree.ready
|
||||||
from InvenTree.version import inventreeVersion
|
from InvenTree.version import inventreeVersion
|
||||||
|
|
||||||
# Logger configuration
|
# Logger configuration
|
||||||
@ -42,6 +43,9 @@ def setup_tracing(
|
|||||||
resources_input: The resources to send with the traces.
|
resources_input: The resources to send with the traces.
|
||||||
console: Whether to output the traces to the console.
|
console: Whether to output the traces to the console.
|
||||||
"""
|
"""
|
||||||
|
if InvenTree.ready.isImportingData() or InvenTree.ready.isRunningMigrations():
|
||||||
|
return
|
||||||
|
|
||||||
if resources_input is None:
|
if resources_input is None:
|
||||||
resources_input = {}
|
resources_input = {}
|
||||||
if auth is None:
|
if auth is None:
|
||||||
|
14
tasks.py
14
tasks.py
@ -672,6 +672,20 @@ def wait(c):
|
|||||||
return manage(c, 'wait_for_db')
|
return manage(c, 'wait_for_db')
|
||||||
|
|
||||||
|
|
||||||
|
@task(pre=[wait], help={'address': 'Server address:port (default=0.0.0.0:8000)'})
|
||||||
|
def gunicorn(c, address='0.0.0.0:8000'):
|
||||||
|
"""Launch a gunicorn webserver.
|
||||||
|
|
||||||
|
Note: This server will not auto-reload in response to code changes.
|
||||||
|
"""
|
||||||
|
c.run(
|
||||||
|
'gunicorn -c ./docker/gunicorn.conf.py InvenTree.wsgi -b {address} --chdir ./InvenTree'.format(
|
||||||
|
address=address
|
||||||
|
),
|
||||||
|
pty=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@task(pre=[wait], help={'address': 'Server address:port (default=127.0.0.1:8000)'})
|
@task(pre=[wait], help={'address': 'Server address:port (default=127.0.0.1:8000)'})
|
||||||
def server(c, address='127.0.0.1:8000'):
|
def server(c, address='127.0.0.1:8000'):
|
||||||
"""Launch a (development) server using Django's in-built webserver.
|
"""Launch a (development) server using Django's in-built webserver.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user