def post(self):
    configured = self._check_config_or_send_error()
    if (not configured):
        return
    try:
        op = _CreateTaskOperation.from_str(self.request.get('request'))
    except:
        self._send_json_response(400, 'Bad request')
        return
    ticket = Manager.create(user_id=op.user_id)
    op.update({_TICKET: ticket})
    if (not op.ready()):
        self._send_json_response(500, 'Unable to compose request for worker')
        return
    (code, response) = _WorkerPool.create_task(op)
    if self._worker_locked(response):
        (code, response) = self._retry_create_task(response, op)
        if (code != 200):
            Manager.mark_failed(ticket)
            self._send_json_response(500, self._get_payload(response))
            return
    request_failed = (code != 200)
    ticket_mismatch = (self._get_ticket(response) != ticket)
    if (request_failed or ticket_mismatch):
        response = ('Ticket mismatch' if ticket_mismatch else 'Worker failed')
        Manager.mark_failed(ticket)
        self._send_json_response(500, response)
    else:
        Manager.mark_running(ticket, self._get_worker_id(response))
        self._send_json_response(code, response)
def post(self):
    configured = self._check_config_or_send_error()
    if (not configured):
        return
    try:
        op = _CreateTaskOperation.from_str(self.request.get('request'))
    except:
        self._send_json_response(400, 'Bad request')
        return
    ticket = Manager.create(user_id=op.user_id)
    op.update({_TICKET: ticket})
    if (not op.ready()):
        self._send_json_response(500, 'Unable to compose request for worker')
        return
    (code, response) = _WorkerPool.create_task(op)
    if self._worker_locked(response):
        (code, response) = self._retry_create_task(response, op)
        if (code != 200):
            Manager.mark_failed(ticket)
            self._send_json_response(500, self._get_payload(response))
            return
    request_failed = (code != 200)
    ticket_mismatch = (self._get_ticket(response) != ticket)
    if (request_failed or ticket_mismatch):
        response = ('Ticket mismatch' if ticket_mismatch else 'Worker failed')
        Manager.mark_failed(ticket)
        self._send_json_response(500, response)
    else:
        Manager.mark_running(ticket, self._get_worker_id(response))
        self._send_json_response(code, response)