func (self *HealthcheckController) Update(c *gin.Context) {
	username := self.CurrentUser(c)

	if username == "" {
		c.Redirect(http.StatusFound, "/")

		return
	}

	appName := c.Param("appName")
	path := c.PostForm("path")

	interval, err := strconv.Atoi(c.PostForm("interval"))
	if err != nil {
		fmt.Fprintf(os.Stderr, "%+v\n", err)

		c.HTML(http.StatusBadRequest, "apps.tmpl", gin.H{
			"alert":   true,
			"error":   true,
			"message": "healthcheck interval is invalid.",
		})

		return
	}

	maxTry, err := strconv.Atoi(c.PostForm("maxTry"))
	if err != nil {
		fmt.Fprintf(os.Stderr, "%+v\n", err)

		c.HTML(http.StatusBadRequest, "apps.tmpl", gin.H{
			"alert":   true,
			"error":   true,
			"message": "healthcheck maxTry is invalid.",
		})

		return
	}

	hc := healthcheck.NewHealthcheck(path, interval, maxTry)

	if err := healthcheck.Update(self.etcd, username, appName, hc); err != nil {
		c.HTML(http.StatusInternalServerError, "app.tmpl", gin.H{
			"alert":   true,
			"error":   true,
			"message": "Failed to update healthcheck.",
		})

		return
	}

	c.Redirect(http.StatusSeeOther, "/apps/"+appName)
}
Beispiel #2
0
func Create(etcd *store.Etcd, username, appName string) error {
	appKey := "/paus/users/" + username + "/apps/" + appName

	if err := etcd.Mkdir(appKey); err != nil {
		return err
	}

	for _, resource := range []string{"build-args", "envs", "deployments"} {
		if err := etcd.Mkdir(appKey + "/" + resource); err != nil {
			return err
		}
	}

	hc := healthcheck.NewHealthcheck(defaultHealthcheckPath, defaultHealthcheckInterval, defaultHealthcheckMaxTry)

	if err := healthcheck.Create(etcd, username, appName, hc); err != nil {
		return err
	}

	return nil
}