Ejemplo n.º 1
0
// This one runs synchronously too
func (w *webSocketHandler) restStateHandler(isStart, isEnd bool, res api.Result, clientID string) {
	if isStart {
		// init the filter to allow it to work correctly
		w.statsFilter.LastResultShownAt = time.Now()
	}

	// ignore this one if it is no OK to show it
	if res != nil {
		if _, prio := res.Info(); !w.statsFilter.OK(prio) {
			return
		}
		// we only care about actual results, and not other events we get, like state changes
		w.statsFilter.LastResultShownAt = time.Now()
	}

	m := jsonMessage{ClientID: clientID}
	if isStart {
		m.State = StateBegin
	} else if isEnd {
		m.State = StateFinished
	} else {
		m.fromResult(res)
	}

	w.jsonBroadcasts <- m.String()
}
Ejemplo n.º 2
0
func (m *jsonMessage) fromResult(r api.Result) {
	if r == nil {
		m.State = StateChanged
	} else {
		m.Message, m.Importance = r.Info()
		if r.Error() != nil {
			m.Error = r.Error().Error()
		}
		m.State = StateResult
	}
}