2024-02-19 09:09:30 +00:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
2024-02-20 10:24:04 +00:00
|
|
|
"context"
|
2024-02-19 09:09:30 +00:00
|
|
|
"net/http"
|
2024-02-20 10:24:04 +00:00
|
|
|
|
|
|
|
"code.tjo.space/mentos1386/zdravko/internal/models"
|
|
|
|
"code.tjo.space/mentos1386/zdravko/internal/services"
|
|
|
|
"github.com/labstack/echo/v4"
|
2024-02-19 09:09:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ApiV1WorkersConnectGETResponse struct {
|
|
|
|
Endpoint string `json:"endpoint"`
|
|
|
|
Group string `json:"group"`
|
|
|
|
Slug string `json:"slug"`
|
|
|
|
}
|
|
|
|
|
2024-02-20 10:24:04 +00:00
|
|
|
func (h *BaseHandler) ApiV1WorkersConnectGET(c echo.Context) error {
|
|
|
|
cc := c.(AuthenticatedContext)
|
2024-02-19 09:09:30 +00:00
|
|
|
|
|
|
|
response := ApiV1WorkersConnectGETResponse{
|
|
|
|
Endpoint: h.config.Temporal.ServerHost,
|
2024-02-20 10:24:04 +00:00
|
|
|
Group: cc.Principal.Worker.Group,
|
|
|
|
Slug: cc.Principal.Worker.Slug,
|
2024-02-19 09:09:30 +00:00
|
|
|
}
|
|
|
|
|
2024-02-20 10:24:04 +00:00
|
|
|
return c.JSON(http.StatusOK, response)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Can we instead get this from the Workflow outcome?
|
|
|
|
//
|
|
|
|
// To somehow listen for the outcomes and then store them automatically.
|
|
|
|
func (h *BaseHandler) ApiV1HealthchecksHistoryPOST(c echo.Context) error {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
slug := c.Param("slug")
|
|
|
|
|
|
|
|
healthcheck, err := services.GetHealthcheckHttp(ctx, h.query, slug)
|
2024-02-19 09:09:30 +00:00
|
|
|
if err != nil {
|
2024-02-20 10:24:04 +00:00
|
|
|
return err
|
2024-02-19 09:09:30 +00:00
|
|
|
}
|
|
|
|
|
2024-02-20 10:24:04 +00:00
|
|
|
err = h.query.HealthcheckHttp.History.Model(healthcheck).Append(
|
|
|
|
&models.HealthcheckHttpHistory{
|
|
|
|
Status: "UP",
|
|
|
|
})
|
2024-02-19 09:09:30 +00:00
|
|
|
if err != nil {
|
2024-02-20 10:24:04 +00:00
|
|
|
return err
|
2024-02-19 09:09:30 +00:00
|
|
|
}
|
2024-02-20 10:24:04 +00:00
|
|
|
|
|
|
|
return c.JSON(http.StatusCreated, map[string]string{"status": "ok"})
|
2024-02-19 09:09:30 +00:00
|
|
|
}
|