mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-01 13:06:45 +00:00
Improvements for docker / gunicorn (#4031)
* Additional options for gunicorn configuration file (in docker): Ref: https://pythonspeed.com/articles/gunicorn-in-docker/ * Catch potential error on startup * Tweak log message for docker * Wrap news feed update in try block
This commit is contained in:
parent
cd29ddaf12
commit
6b659ba22f
@ -5,6 +5,7 @@ from datetime import datetime, timedelta
|
|||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import AppRegistryNotReady
|
from django.core.exceptions import AppRegistryNotReady
|
||||||
|
from django.db.utils import IntegrityError, OperationalError
|
||||||
|
|
||||||
import feedparser
|
import feedparser
|
||||||
|
|
||||||
@ -57,13 +58,17 @@ def update_news_feed():
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# Create entry
|
# Create entry
|
||||||
NewsFeedEntry.objects.create(
|
try:
|
||||||
feed_id=entry.id,
|
NewsFeedEntry.objects.create(
|
||||||
title=entry.title,
|
feed_id=entry.id,
|
||||||
link=entry.link,
|
title=entry.title,
|
||||||
published=entry.published,
|
link=entry.link,
|
||||||
author=entry.author,
|
published=entry.published,
|
||||||
summary=entry.summary,
|
author=entry.author,
|
||||||
)
|
summary=entry.summary,
|
||||||
|
)
|
||||||
|
except (IntegrityError, OperationalError):
|
||||||
|
# Sometimes errors-out on database start-up
|
||||||
|
pass
|
||||||
|
|
||||||
logger.info('update_news_feed: Sync done')
|
logger.info('update_news_feed: Sync done')
|
||||||
|
@ -10,6 +10,7 @@ from pathlib import Path
|
|||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import AppRegistryNotReady
|
from django.core.exceptions import AppRegistryNotReady
|
||||||
|
from django.db.utils import OperationalError
|
||||||
|
|
||||||
from InvenTree.ready import canAppAccessDatabase
|
from InvenTree.ready import canAppAccessDatabase
|
||||||
|
|
||||||
@ -35,18 +36,18 @@ class LabelConfig(AppConfig):
|
|||||||
def ready(self):
|
def ready(self):
|
||||||
"""This function is called whenever the label app is loaded."""
|
"""This function is called whenever the label app is loaded."""
|
||||||
if canAppAccessDatabase():
|
if canAppAccessDatabase():
|
||||||
self.create_labels() # pragma: no cover
|
|
||||||
|
try:
|
||||||
|
self.create_labels() # pragma: no cover
|
||||||
|
except (AppRegistryNotReady, OperationalError):
|
||||||
|
# Database might not yet be ready
|
||||||
|
warnings.warn('Database was not ready for creating labels')
|
||||||
|
|
||||||
def create_labels(self):
|
def create_labels(self):
|
||||||
"""Create all default templates."""
|
"""Create all default templates."""
|
||||||
# Test if models are ready
|
# Test if models are ready
|
||||||
try:
|
from .models import PartLabel, StockItemLabel, StockLocationLabel
|
||||||
from .models import PartLabel, StockItemLabel, StockLocationLabel
|
assert bool(StockLocationLabel is not None)
|
||||||
assert bool(StockLocationLabel is not None)
|
|
||||||
except AppRegistryNotReady: # pragma: no cover
|
|
||||||
# Database might not yet be ready
|
|
||||||
warnings.warn('Database was not ready for creating labels')
|
|
||||||
return
|
|
||||||
|
|
||||||
# Create the categories
|
# Create the categories
|
||||||
self.create_labels_category(
|
self.create_labels_category(
|
||||||
@ -62,6 +63,7 @@ class LabelConfig(AppConfig):
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
self.create_labels_category(
|
self.create_labels_category(
|
||||||
StockLocationLabel,
|
StockLocationLabel,
|
||||||
'stocklocation',
|
'stocklocation',
|
||||||
@ -82,6 +84,7 @@ class LabelConfig(AppConfig):
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
self.create_labels_category(
|
self.create_labels_category(
|
||||||
PartLabel,
|
PartLabel,
|
||||||
'part',
|
'part',
|
||||||
|
@ -4,7 +4,17 @@ import logging
|
|||||||
import multiprocessing
|
import multiprocessing
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
# Logger configuration
|
||||||
logger = logging.getLogger('inventree')
|
logger = logging.getLogger('inventree')
|
||||||
|
accesslog = '-'
|
||||||
|
errorlog = '-'
|
||||||
|
loglevel = os.environ.get('INVENTREE_LOG_LEVEL', 'warning').lower()
|
||||||
|
capture_output = True
|
||||||
|
|
||||||
|
# Worker configuration
|
||||||
|
worker_class = 'gevent' # Allow multi-threading support
|
||||||
|
worker_tmp_dir = '/dev/shm' # Write temp file to RAM (faster)
|
||||||
|
threads = 4
|
||||||
|
|
||||||
workers = os.environ.get('INVENTREE_GUNICORN_WORKERS', None)
|
workers = os.environ.get('INVENTREE_GUNICORN_WORKERS', None)
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ fi
|
|||||||
|
|
||||||
# Check if "config.yaml" has been copied into the correct location
|
# Check if "config.yaml" has been copied into the correct location
|
||||||
if test -f "$INVENTREE_CONFIG_FILE"; then
|
if test -f "$INVENTREE_CONFIG_FILE"; then
|
||||||
echo "$INVENTREE_CONFIG_FILE exists - skipping"
|
echo "Loading config file : $INVENTREE_CONFIG_FILE"
|
||||||
else
|
else
|
||||||
echo "Copying config file to $INVENTREE_CONFIG_FILE"
|
echo "Copying config file to $INVENTREE_CONFIG_FILE"
|
||||||
cp $INVENTREE_HOME/InvenTree/config_template.yaml $INVENTREE_CONFIG_FILE
|
cp $INVENTREE_HOME/InvenTree/config_template.yaml $INVENTREE_CONFIG_FILE
|
||||||
|
@ -14,3 +14,4 @@ mariadb>=1.0.7,<1.1.0
|
|||||||
|
|
||||||
# gunicorn web server
|
# gunicorn web server
|
||||||
gunicorn>=20.1.0
|
gunicorn>=20.1.0
|
||||||
|
gevent>=22.10.2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user