Commit 1acd71c9 authored by Stefano Alberto Russo's avatar Stefano Alberto Russo
Browse files

Added check if the task interface is up, and marked the task status...

Added check if the task interface is up, and marked the task status accordingly - including graying out the connect button if not up yet.
parent a752ce53
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -44,10 +44,10 @@
            <!-- <a href="/computing/?uuid={{ task.computing.uuid }}" no_style="color:{{task.computing.color}}"><i class="fa fa-external-link" ></i></a><br/> -->           
            
            <div style="margin-top:2px">
            {% if task.status == "running" %}
            {% if task.verified_status == "running" %}
             <b>Status:</b> <font color="green">running</font>
            {% else %}
             <b>Status:</b> {{ task.status }}
             <b>Status:</b> {{ task.verified_status }}
            {% endif %}
            </div>
            </div>
@@ -63,7 +63,7 @@
            
            <!-- Connect -->
            {% if task.interface_port %}
            {% if task.status == "running" %}
            {% if task.verified_status == "running" %}
            <a href="/task_connect/?uuid={{task.uuid}}" class="btn btn-connect" target="_blank">Connect</a>
            {% else %}
            <a href="" class="btn btn-disabled">Connect</a>  
+30 −2
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ import os
import uuid
import json
import requests
import socket
import subprocess
import base64
from django.conf import settings
@@ -341,6 +342,30 @@ def account(request):
#  Tasks view
#=========================

def set_verified_status(task):
    # Chech status with ping
    if task.status == 'running':
        logger.debug('Task is running, check if startup completed')

        logger.debug('Trying to establish connection on: "{}:{}"'.format(task.interface_ip,task.interface_port))
        s = socket.socket()
        try:
            s.settimeout(1)
            s.connect((task.interface_ip, task.interface_port))
            # Not necessary, we just check that the container interfcae is up
            #if not s.recv(10):
            #    logger.debug('No data read from socket')
            #    raise Exception('Could not read any data from socket')
        except Exception as e:
            logger.debug('Could not connect to socket')
            task.verified_status = 'starting up...'
        else:
            task.verified_status = 'running'
        finally:
            s.close()
    else:
        task.verified_status = task.status

@private_view
def tasks(request):

@@ -367,6 +392,8 @@ def tasks(request):
                task = Task.objects.get(user=request.user, uuid=uuid)
            except Task.DoesNotExist:
                raise ErrorMessage('Task does not exists or no access rights')
            
            set_verified_status(task)
            data['task'] = task
            
            #  Task actions
@@ -447,6 +474,7 @@ def tasks(request):
        # Update task statuses
        for task in tasks:
            task.update_status()
            set_verified_status(task)
        
        # Set task and tasks variables
        data['task']  = None