예제 #1
0
func (s *server) GetStatus(project string) map[string]*StatusResult {
	result := make(map[string]*StatusResult, 0)

	for name, p := range s.config.Projects {
		if project != "" && project != name {
			continue
		}

		record := &StatusResult{Project: p}
		sl, errs := p.Status()
		if len(errs) != 0 {
			for _, err := range errs {
				core.Error(err.Error(), "project", p)
			}

			record.Error = errs
		} else {
			record.Status = make(map[string]*StatusRecord, 0)
			for _, s := range sl {
				record.Status[s.Environment.Name] = &StatusRecord{s.LastRevision.Get(), s}
			}
		}

		result[p.Name] = record
	}

	fmt.Println("terminado", result)
	return result
}
예제 #2
0
func (s *server) DoDeploy(w io.Writer, project, environment string, force bool) *DeployResult {
	start := time.Now()
	r := &DeployResult{}
	defer func() {
		r.Elapsed = time.Since(start)
	}()

	core.Info(
		"Starting deploy",
		"project", project, "environment", environment, "force", force,
	)

	p, ok := s.config.Projects[project]
	if !ok {
		core.Error("Project not found", "project", p)

		r.Errors = []error{ErrProjectNotFound}
		return r
	}

	r.Errors = p.Deploy(environment, w, force)
	if len(r.Errors) == 0 {
		r.Done = true
		core.Info("Deploy success", "project", p, "environment", environment)
	} else {
		for _, e := range r.Errors {
			core.Critical(e.Error(), "project", p, "environment", environment)
		}
	}

	return r
}
예제 #3
0
func (s *server) HandleDeploy(msg Message, session sockjs.Session) {
	force := true
	project, ok := msg.Request["project"]
	if !ok {
		core.Error("Missing project", "request", "deploy")
		return
	}

	environment, ok := msg.Request["environment"]
	if !ok {
		core.Error("Missing environment", "request", "deploy")
		return
	}

	now := time.Now()

	writer := NewSockJSWriter(s.sockjs, "deploy")
	writer.SetFormater(func(raw []byte) []byte {
		str, _ := json.Marshal(map[string]string{
			"environment": environment,
			"project":     project,
			"date":        now.String(),
			"log":         string(raw),
		})

		return str
	})

	go func(session sockjs.Session) {
		time.Sleep(50 * time.Millisecond)
		s.EmitProjects(session)
	}(session)

	s.DoDeploy(writer, project, environment, force)
	s.EmitProjects(session)
}
예제 #4
0
func (s *SockJS) Send(event, data interface{}, isJSON bool) {
	var result []byte
	if isJSON {
		result = data.([]byte)
	} else {
		var err error
		result, err = json.Marshal(data)
		if err != nil {
			core.Error(fmt.Sprintf("Error SockJS send: %q", err.Error()))
			return
		}
	}

	raw := fmt.Sprintf("{\"event\":\"%s\", \"result\":%s}", event, result)

	for _, session := range s.sessions {
		session.Send(raw)
	}
}