Ejemplo n.º 1
0
def heartbeat_check():
    '''
    Find the node with the oldest hearbeat timestamp and query it
    '''
    logging.debug('DEBUG: heartbeat_check()')
    siblings = Sibling.objects.filter().order_by('last_heartbeat')
    if siblings:
        oldest = siblings[0]
        try:
            lock = Lock.acquire_lock(u''.join(['heartbeat_check', oldest.uuid]), 20)
            node = RemoteCall(uuid=oldest.uuid)
            oldest.last_heartbeat = datetime.datetime.now()
            response = node.heartbeat()
            oldest.cpuload = int(float(response['cpuload']))
            oldest.status = NODE_STATUS_UP
            oldest.failure_count = 0
            oldest.save()
            lock.release()
        except LockError:
            pass
        except HeartbeatError:
            oldest.status = NODE_STATUS_DOWN
            oldest.failure_count += 1
            oldest.save()
            if oldest.failure_count > HEARTBEAT_FAILURE_THRESHOLD:
                oldest.delete()

            lock.release()