mirror of https://github.com/jumpserver/jumpserver
				
				
				
			
							parent
							
								
									47d0882090
								
							
						
					
					
						commit
						fb1978a40b
					
				| 
						 | 
				
			
			@ -53,7 +53,7 @@ class Status(models.Model):
 | 
			
		|||
 | 
			
		||||
    def save(self, force_insert=False, force_update=False, using=None,
 | 
			
		||||
             update_fields=None):
 | 
			
		||||
        self.terminal.set_alive(ttl=120)
 | 
			
		||||
        self.terminal.set_alive(ttl=60 * 3)
 | 
			
		||||
        return self.save_to_cache()
 | 
			
		||||
 | 
			
		||||
    def save_to_cache(self):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,3 @@
 | 
			
		|||
import time
 | 
			
		||||
 | 
			
		||||
from django.conf import settings
 | 
			
		||||
from django.core.cache import cache
 | 
			
		||||
from django.db import models
 | 
			
		||||
| 
						 | 
				
			
			@ -11,6 +9,7 @@ from common.utils import get_logger, lazyproperty
 | 
			
		|||
from orgs.utils import tmp_to_root_org
 | 
			
		||||
from terminal.const import TerminalType as TypeChoices
 | 
			
		||||
from users.models import User
 | 
			
		||||
from .status import Status
 | 
			
		||||
from ..session import Session
 | 
			
		||||
 | 
			
		||||
logger = get_logger(__file__)
 | 
			
		||||
| 
						 | 
				
			
			@ -23,7 +22,7 @@ class TerminalStatusMixin:
 | 
			
		|||
 | 
			
		||||
    @lazyproperty
 | 
			
		||||
    def last_stat(self):
 | 
			
		||||
        return self.status_set.order_by('date_created').last()
 | 
			
		||||
        return Status.get_terminal_latest_stat(self)
 | 
			
		||||
 | 
			
		||||
    @lazyproperty
 | 
			
		||||
    def load(self):
 | 
			
		||||
| 
						 | 
				
			
			@ -32,11 +31,10 @@ class TerminalStatusMixin:
 | 
			
		|||
 | 
			
		||||
    @property
 | 
			
		||||
    def is_alive(self):
 | 
			
		||||
        if not self.last_stat:
 | 
			
		||||
            return False
 | 
			
		||||
        return time.time() - self.last_stat.date_created.timestamp() < 150
 | 
			
		||||
        key = self.ALIVE_KEY.format(self.id)
 | 
			
		||||
        return cache.get(key, False)
 | 
			
		||||
 | 
			
		||||
    def set_alive(self, ttl=120):
 | 
			
		||||
    def set_alive(self, ttl=60 * 3):
 | 
			
		||||
        key = self.ALIVE_KEY.format(self.id)
 | 
			
		||||
        cache.set(key, True, ttl)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,5 @@
 | 
			
		|||
# -*- coding: utf-8 -*-
 | 
			
		||||
#
 | 
			
		||||
import time
 | 
			
		||||
from itertools import groupby
 | 
			
		||||
 | 
			
		||||
from common.utils import get_logger
 | 
			
		||||
| 
						 | 
				
			
			@ -40,7 +39,7 @@ class ComputeLoadUtil:
 | 
			
		|||
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def compute_load(cls, stat):
 | 
			
		||||
        if not stat or time.time() - stat.date_created.timestamp() > 150:
 | 
			
		||||
        if not stat:
 | 
			
		||||
            return ComponentLoad.offline
 | 
			
		||||
        system_status_values = cls._compute_system_stat_status(stat).values()
 | 
			
		||||
        if ComponentLoad.critical in system_status_values:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue