kopia lustrzana https://github.com/OpenDroneMap/WebODM
Add NODE_OPTIMISTIC_MODE
rodzic
82f3408b94
commit
c0fe407157
|
@ -6,7 +6,7 @@ from rest_framework.response import Response
|
|||
from rest_framework.views import APIView
|
||||
|
||||
from nodeodm.models import ProcessingNode
|
||||
|
||||
from webodm import settings
|
||||
|
||||
class ProcessingNodeSerializer(serializers.ModelSerializer):
|
||||
online = serializers.SerializerMethodField()
|
||||
|
@ -49,6 +49,18 @@ class ProcessingNodeViewSet(viewsets.ModelViewSet):
|
|||
serializer_class = ProcessingNodeSerializer
|
||||
queryset = ProcessingNode.objects.all()
|
||||
|
||||
def list(self, request, *args, **kwargs):
|
||||
queryset = self.filter_queryset(self.get_queryset())
|
||||
|
||||
if settings.UI_MAX_PROCESSING_NODES is not None:
|
||||
queryset = queryset[:settings.UI_MAX_PROCESSING_NODES]
|
||||
|
||||
if settings.NODE_OPTIMISTIC_MODE:
|
||||
for pn in queryset:
|
||||
pn.update_node_info()
|
||||
|
||||
serializer = self.get_serializer(queryset, many=True)
|
||||
return Response(serializer.data)
|
||||
|
||||
class ProcessingNodeOptionsView(APIView):
|
||||
"""
|
||||
|
|
|
@ -86,7 +86,7 @@ class EditTaskForm extends React.Component {
|
|||
}
|
||||
|
||||
checkFilesCount(filesCount){
|
||||
if (!this.state.selectedNode) return false;
|
||||
if (!this.state.selectedNode) return true;
|
||||
if (filesCount === 0) return true;
|
||||
if (this.state.selectedNode.max_images === null) return true;
|
||||
return this.state.selectedNode.max_images >= filesCount;
|
||||
|
|
|
@ -460,6 +460,18 @@ class TestApi(BootTestCase):
|
|||
self.assertTrue(len(res.data) == 1)
|
||||
self.assertTrue(res.data[0]['name'] == 'a')
|
||||
|
||||
# Test optimistic mode
|
||||
self.assertFalse(p4.is_online())
|
||||
|
||||
settings.NODE_OPTIMISTIC_MODE = True
|
||||
|
||||
self.assertTrue(p4.is_online())
|
||||
res = client.get('/api/processingnodes/')
|
||||
self.assertEqual(len(res.data), 3)
|
||||
for nodes in res.data:
|
||||
self.assertTrue(nodes['online'])
|
||||
|
||||
settings.NODE_OPTIMISTIC_MODE = False
|
||||
|
||||
def test_token_auth(self):
|
||||
client = APIClient()
|
||||
|
|
|
@ -101,6 +101,10 @@ class TestApp(BootTestCase):
|
|||
self.assertEqual(res.content.decode("utf-8").count('href="/processingnode/'), 3)
|
||||
self.assertTemplateUsed(res, 'app/dashboard.html')
|
||||
|
||||
# The API should return 3 nodes
|
||||
res = c.get('/api/processingnodes/')
|
||||
self.assertEqual(len(res.data), 3)
|
||||
|
||||
# We can change that with a setting
|
||||
settings.UI_MAX_PROCESSING_NODES = 1
|
||||
|
||||
|
@ -108,6 +112,11 @@ class TestApp(BootTestCase):
|
|||
self.assertEqual(res.content.decode("utf-8").count('href="/processingnode/'), 1)
|
||||
self.assertTemplateUsed(res, 'app/dashboard.html')
|
||||
|
||||
res = c.get('/api/processingnodes/')
|
||||
self.assertEqual(len(res.data), 1)
|
||||
|
||||
settings.UI_MAX_PROCESSING_NODES = None
|
||||
|
||||
res = c.get('/processingnode/9999/')
|
||||
self.assertTrue(res.status_code == 404)
|
||||
|
||||
|
|
|
@ -52,6 +52,9 @@ class ProcessingNode(models.Model):
|
|||
.order_by('queue_count').first()
|
||||
|
||||
def is_online(self):
|
||||
if settings.NODE_OPTIMISTIC_MODE:
|
||||
return True
|
||||
|
||||
return self.last_refreshed is not None and \
|
||||
self.last_refreshed >= timezone.now() - timedelta(minutes=settings.NODE_OFFLINE_MINUTES)
|
||||
|
||||
|
|
|
@ -389,7 +389,11 @@ CACHES = {
|
|||
|
||||
# Number of minutes a processing node hasn't been seen
|
||||
# before it should be considered offline
|
||||
NODE_OFFLINE_MINUTES = 5
|
||||
NODE_OFFLINE_MINUTES = 5
|
||||
|
||||
# When turned on, updates nodes information only when necessary
|
||||
# and assumes that all nodes are always online, avoiding polling
|
||||
NODE_OPTIMISTIC_MODE = False
|
||||
|
||||
# URL to external auth endpoint
|
||||
EXTERNAL_AUTH_ENDPOINT = ''
|
||||
|
@ -401,7 +405,7 @@ RESET_PASSWORD_LINK = ''
|
|||
# from an account that is exceeding a disk quota
|
||||
QUOTA_EXCEEDED_GRACE_PERIOD = 8
|
||||
|
||||
# Maximum number of processing nodes to show in the "Processing Nodes" menu
|
||||
# Maximum number of processing nodes to show in "Processing Nodes" menus/dropdowns
|
||||
UI_MAX_PROCESSING_NODES = None
|
||||
|
||||
if TESTING or FLUSHING:
|
||||
|
|
|
@ -33,6 +33,9 @@ TestSafeAsyncResult = worker.celery.MockAsyncResult if settings.TESTING else app
|
|||
|
||||
@app.task
|
||||
def update_nodes_info():
|
||||
if settings.NODE_OPTIMISTIC_MODE:
|
||||
return
|
||||
|
||||
processing_nodes = ProcessingNode.objects.all()
|
||||
for processing_node in processing_nodes:
|
||||
processing_node.update_node_info()
|
||||
|
|
Ładowanie…
Reference in New Issue