2016-09-20 22:18:10 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from django.db import models
|
2016-09-21 20:04:47 +00:00
|
|
|
from django.contrib.postgres import fields
|
2016-09-21 20:54:22 +00:00
|
|
|
from .api_client import ApiClient
|
2016-09-20 22:18:10 +00:00
|
|
|
|
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, help_text="API version used by the node")
|
|
|
|
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
|
|
|
|
if self.hostname != None and self.port != None:
|
|
|
|
print("HI!")
|
|
|
|
self.api_client = ApiClient(self.hostname, self.port)
|
|
|
|
|
2016-09-21 20:04:47 +00:00
|
|
|
def __str__(self):
|
2016-09-21 20:54:22 +00:00
|
|
|
print("OH!");
|
|
|
|
self.update_info()
|
2016-09-21 20:04:47 +00:00
|
|
|
return '{}:{}'.format(self.hostname, self.port)
|
2016-09-21 20:54:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
def update_info(self):
|
|
|
|
"""
|
|
|
|
Retrieves information from the node
|
|
|
|
and saves it into the database
|
|
|
|
"""
|
|
|
|
print(self.api_client.info())
|