OpenDroneMap-WebODM/nodeodm/models.py

52 wiersze
2.0 KiB
Python
Czysty Zwykły widok Historia

from __future__ import unicode_literals
from django.db import models
2016-09-21 20:04:47 +00:00
from django.contrib.postgres import fields
from django.utils import timezone
2016-09-21 20:54:22 +00:00
from .api_client import ApiClient
import json
2016-09-21 20:04:47 +00:00
class ProcessingNode(models.Model):
hostname = models.CharField(max_length=255, help_text="Hostname where the node is located (can be an internal hostname as well)")
port = models.PositiveIntegerField(help_text="Port that connects to the node's API")
api_version = models.CharField(max_length=32, null=True, help_text="API version used by the node")
2016-09-21 20:04:47 +00:00
last_refreshed = models.DateTimeField(null=True, help_text="When was the information about this node last retrieved?")
queue_count = models.PositiveIntegerField(default=0, help_text="Number of tasks currently being processed by this node (as reported by the node itself)")
available_options = fields.JSONField(default=dict(), help_text="Description of the options that can be used for processing")
2016-09-21 20:54:22 +00:00
def __init__(self, *args, **kwargs):
super(ProcessingNode, self).__init__(*args, **kwargs)
# Initialize api client
self.api_client = ApiClient(self.hostname, self.port)
2016-09-21 20:54:22 +00:00
2016-09-21 20:04:47 +00:00
def __str__(self):
return '{}:{}'.format(self.hostname, self.port)
2016-09-21 20:54:22 +00:00
def update_node_info(self):
2016-09-21 20:54:22 +00:00
"""
Retrieves information and options from the node API
and saves it into the database.
:returns: True if information could be updated, False otherwise
2016-09-21 20:54:22 +00:00
"""
info = self.api_client.info()
if info != None:
self.api_version = info['version']
self.queue_count = info['taskQueueCount']
options = self.api_client.options()
if options != None:
self.available_options = options
self.last_refreshed = timezone.now()
self.save()
return True
return False
def get_available_options_json(self):
"""
:returns available options in JSON string format
"""
return json.dumps(self.available_options)