def get(self):
    configured = self._check_config_or_send_error()
    if (not configured):
        return
    try:
        op = _GetTaskOperation.from_str(self.request.get('request'))
    except:
        self._send_json_response(400, 'Bad request')
        return
    task = None
    try:
        task = Manager.get(op.ticket)
    except ValueError:
        pass
    if (not task):
        self._send_json_response(404, ('Task not found for ticket %s' % op.ticket))
        return
    if task.is_done():
        self._send_json_response(200, task.for_json())
        return
    op.update({_WORKER_ID: task.worker_id})
    if (not op.ready()):
        self._send_json_response(500, 'Unable to compose request for worker')
        return
    (code, response) = _WorkerPool.get_task(op)
    if (code != 200):
        self._send_json_response(code, response)
        return
    status = self._get_status(response)
    if (status is None):
        self._send_json_response(500, 'Worker sent partial response')
        return
    elif _ExternalTask.is_status_terminal(status):
        try:
            payload = self._get_task_payload(response)
            Manager.mark_done(op.ticket, status, payload)
        except:
            self._send_json_response(500, 'Invalid worker status or payload too big')
            return
    self._send_json_response(*_WorkerPool.get_task(op))
def get(self):
    configured = self._check_config_or_send_error()
    if (not configured):
        return
    try:
        op = _GetTaskOperation.from_str(self.request.get('request'))
    except:
        self._send_json_response(400, 'Bad request')
        return
    task = None
    try:
        task = Manager.get(op.ticket)
    except ValueError:
        pass
    if (not task):
        self._send_json_response(404, ('Task not found for ticket %s' % op.ticket))
        return
    if task.is_done():
        self._send_json_response(200, task.for_json())
        return
    op.update({_WORKER_ID: task.worker_id})
    if (not op.ready()):
        self._send_json_response(500, 'Unable to compose request for worker')
        return
    (code, response) = _WorkerPool.get_task(op)
    if (code != 200):
        self._send_json_response(code, response)
        return
    status = self._get_status(response)
    if (status is None):
        self._send_json_response(500, 'Worker sent partial response')
        return
    elif _ExternalTask.is_status_terminal(status):
        try:
            payload = self._get_task_payload(response)
            Manager.mark_done(op.ticket, status, payload)
        except:
            self._send_json_response(500, 'Invalid worker status or payload too big')
            return
    self._send_json_response(*_WorkerPool.get_task(op))