Пример #1
0
def cancel_job(request):
    """
    Cancel nhmmer search.

    HTTP responses:
    * 200 - job cancelled
    * 400 - incorrect input
    * 500 - internal error
    """
    proxy_result = nhmmer_proxy(request)
    if proxy_result:
        return proxy_result

    msg = messages['cancel']

    job_id = request.GET.get('id', '')
    if not job_id:
        status = 400
        return Response(msg[status], status=status)

    try:
        # cancel job
        job = get_job(job_id)[0]
        job.cancel()
        # kill nhmmer process
        kill_nhmmer_job(job_id)
        # set query `finished` field
        query = Query.objects.get(id=job_id)
        query.finished = datetime.datetime.now()
        query.save()
        status = 200
        return Response(msg[status], status=status)
    except:
        status = 500
        return Response(msg[status], status=status)
Пример #2
0
def submit_job(request):
    """
    Start nhmmer search.

    HTTP responses:
    * 201 - job submitted
    * 400 - incorrect input
    * 500 - internal error
    """
    proxy_result = nhmmer_proxy(request)
    if proxy_result:
        return proxy_result

    msg = messages['submit']

    if request.method == 'POST':
        query = request.POST.get('q', '')
        description = request.POST.get('description', '')
    elif request.method == 'GET':
        query = request.GET.get('q', '')
        description = request.GET.get('description', '')

    if not query:
        status = 400
        return Response(msg[status]['no_sequence'], status=status)

    if len(query) < MIN_LENGTH:
        status = 400
        return Response(msg[status]['too_short'], status=status)
    elif len(query) > MAX_LENGTH:
        status = 400
        return Response(msg[status]['too_long'], status=status)

    try:
        status = 201
        job_id = enqueue_job(query, description)
        url = request.build_absolute_uri(
            reverse('nhmmer-job-status') +
            '?id=%s' % job_id
        )
        data = {
            'id': job_id,
            'url': url,
        }
        return Response(data, status=status)
    except:
        status = 500
        return Response(msg[status], status=status)
Пример #3
0
def get_status(request):
    """
    Get status of an nhmmer search.

    HTTP responses:
    * 200 - job found
    * 400 - job id not provided in the url
    * 404 - job not found in the queue
    * 500 - internal error
    """
    proxy_result = nhmmer_proxy(request)
    if proxy_result:
        return proxy_result

    msg = messages['status']

    job_id = request.GET.get('id', '')
    if not job_id:
        status = 400
        return Response(msg[status], status=status)

    try:
        job = get_job(job_id)[0]
        if job:
            url = request.build_absolute_uri(
                reverse('nhmmer-job-results') +
                '?id=%s' % job_id
            )
            return Response(StatusSerializer({
                'id': job.id,
                'status': job.get_status(),
                'enqueued_at': job.enqueued_at,
                'ended_at': job.ended_at,
                'expiration': job.meta.get('expiration', None),
                'url': url,
            }).data)
        else:
            status = 404
            return Response(msg[status], status=status)
    except:
        status = 500
        return Response(msg[status], status=status)