Beispiel #1
0
def perform_retrieval(task_id):
    dt = get_and_check_task(task_id)
    if dt is None:
        return 0
    args = dt.arguments
    target = args.get('target', 'query')  # by default target is query
    if target == 'query':
        vector = np.load(
            io.BytesIO(redis_client.get("query_vector_{}".format(
                dt.parent_id))))
        Retrievers.retrieve(dt, args.get('retriever_pk', 20), vector,
                            args.get('count', 20))
    elif target == 'query_region_index_vectors':
        qr_pk_vector = redis_client.hgetall("query_region_vectors_{}".format(
            dt.parent_id))
        for query_region_pk, vector in qr_pk_vector.items():
            vector = np.load(io.BytesIO(vector))
            Retrievers.retrieve(dt,
                                args.get('retriever_pk', 20),
                                vector,
                                args.get('count', 20),
                                region_pk=query_region_pk)
    else:
        raise NotImplementedError(target)
    mark_as_completed(dt)
    return 0
Beispiel #2
0
 def list(self, request, format=None):
     """
     Returns state of the retriever
     """
     retriever_state = redis_client.hgetall("retriever_state")
     if retriever_state:
         return Response({k:json.loads(v) for k,v in retriever_state.items()})
     else:
         return Response({})
Beispiel #3
0
 def get_context_data(self, **kwargs):
     context = super(RetrieverList, self).get_context_data(**kwargs)
     retriever_state = redis_client.hgetall("retriever_state")
     if retriever_state:
         context['retriever_state'] = [json.loads(v) for k,v in retriever_state.items()]
     else:
         context['retriever_state'] = []
     for k in context['retriever_state']:
         k['ts'] = datetime.fromtimestamp(k['ts'],tz=timezone.utc)
     return context
def monitor_system():
    """
    This task used by scheduler to monitor state of the system.
    :return:
    """
    last_action = models.ManagementAction.objects.filter(
        ping_index__isnull=False).last()
    if last_action:
        ping_index = last_action.ping_index + 1
    else:
        ping_index = 0
    # TODO: Handle the case where host manager has not responded to last and itself has died
    _ = app.send_task('manage_host',
                      args=['list', ping_index],
                      exchange='qmanager')
    worker_stats = {
        'alive': 0,
        'transition': 0,
        'dead': models.Worker.objects.filter(alive=False).count()
    }
    for w in models.Worker.objects.filter(alive=True):
        # if worker is not heard from via manager for more than 10 minutes
        # mark it as dead, so that processes_monitor can mark tasks are errored and restart if possible.
        if (timezone.now() - w.last_ping).total_seconds() > 600:
            w.alive = False
            w.save()
            worker_stats['transition'] += 1
        else:
            worker_stats['alive'] += 1
    process_stats = {
        'processes':
        models.DVAPQL.objects.count(),
        'completed_processes':
        models.DVAPQL.objects.filter(completed=True).count(),
        'tasks':
        models.TEvent.objects.count(),
        'pending_tasks':
        models.TEvent.objects.filter(started=False).count(),
        'completed_tasks':
        models.TEvent.objects.filter(started=True, completed=True).count()
    }
    retriever_state = redis_client.hgetall("retriever_state")
    if retriever_state:
        retriever_stats = {
            k: json.loads(v)
            for k, v in retriever_state.items()
        }
    else:
        retriever_stats = {}
    _ = models.SystemState.objects.create(redis_stats=redis_client.info(),
                                          process_stats=process_stats,
                                          retriever_stats=retriever_stats,
                                          worker_stats=worker_stats)