Ejemplo n.º 1
0
func (this *activeHttpRequests) Put(req server.Request) errors.Error {
	this.Lock()
	defer this.Unlock()
	http_req, is_http := req.(*httpRequest)
	if !is_http {
		return errors.NewServiceErrorHttpReq(req.Id().String())
	}
	this.requests[http_req.Id().String()] = http_req
	return nil
}
Ejemplo n.º 2
0
func doActiveRequest(endpoint *HttpEndpoint, w http.ResponseWriter, req *http.Request) (interface{}, errors.Error) {
	vars := mux.Vars(req)
	requestId := vars["request"]

	switch req.Method {
	case "GET":
		request, _ := endpoint.actives.Get(requestId)
		reqMap := map[string]interface{}{}
		reqMap["requestId"] = request.Id().String()
		if request.Statement() != "" {
			reqMap["request.statement"] = request.Statement()
		}
		if request.Prepared() != nil {
			p := request.Prepared()
			reqMap["prepared.name"] = p.Name()
			reqMap["prepared.statement"] = p.Text()
		}
		reqMap["requestTime"] = request.RequestTime()
		reqMap["elapsedTime"] = time.Since(request.RequestTime()).String()
		reqMap["executionTime"] = time.Since(request.ServiceTime()).String()
		reqMap["state"] = request.State()

		// FIXME more stats
		// PhaseTimes() is not in server.Request API
		httpRequest, isHttp := request.(*httpRequest)
		if isHttp {
			for phase, phaseTime := range httpRequest.PhaseTimes() {
				reqMap[phase] = phaseTime.String()
			}
		}
		return reqMap, nil
	case "DELETE":
		if endpoint.actives.Delete(requestId, true) {
			return nil, errors.NewServiceErrorHttpReq(requestId)
		}

		return true, nil
	default:
		return nil, nil
	}
}