Exemple #1
0
func sendStartupData(s *seed.Seed, socket socket, runningState string) {
	messages := []executor.MonitorMessage{}

	// _service block content
	messages = append(messages, executor.MonitorMessage{
		Block: "_service",
		Data:  fmt.Sprintf("<code>%s</code>", s.String()[1:]), // skip the beginning newline in the string
	})

	// _graph block content
	dot, err := dot.ToDot(s, s.Name)
	if err != nil {
		panic(err)
	}
	graphviz := exec.Command("dot", "-Tsvg")
	graphviz.Stdin = bytes.NewBuffer(dot)
	graph, err := graphviz.Output()
	if err != nil {
		panic(err)
	}
	messages = append(messages, executor.MonitorMessage{
		Block: "_graph",
		Data:  string(graph), // skip the beginning newline in the string
	})

	// list of collections for input control
	collections := ""
	for name, _ := range s.Collections {
		collections += fmt.Sprintf("<option value=\"%s\">%s</option>", name, name)
	}
	messages = append(messages, executor.MonitorMessage{
		Block: "_collections",
		Data:  collections,
	})

	// runningState
	messages = append(messages, executor.MonitorMessage{
		Block: "_command",
		Data:  runningState,
	})

	for _, message := range messages {
		data, err := json.Marshal(message)
		if err != nil {
			panic(err)
		}

		socket.Write(data)
	}
}