diff --git a/deploy/fly.toml b/deploy/fly.toml index 294b39d..83f73ae 100644 --- a/deploy/fly.toml +++ b/deploy/fly.toml @@ -16,6 +16,9 @@ primary_region = 'waw' ROOT_URL = 'https://zdravko.mnts.dev' TEMPORAL_SERVER_HOST = 'server.process.zdravko.internal:7233' + TEMPORAL_DATABASE_PATH = '/data/temporal-1.db' + DATABASE_PATH = '/data/zdravko-1.db' + [processes] server = '--temporal --server' worker = '--worker' diff --git a/pkg/server/server.go b/pkg/server/server.go index af431c4..674b372 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -16,13 +16,14 @@ import ( ) type Server struct { - server *http.Server - cfg *config.ServerConfig + echo *echo.Echo + cfg *config.ServerConfig } func NewServer(cfg *config.ServerConfig) (*Server, error) { return &Server{ - cfg: cfg, + cfg: cfg, + echo: echo.New(), }, nil } @@ -31,10 +32,9 @@ func (s *Server) Name() string { } func (s *Server) Start() error { - e := echo.New() - e.Renderer = templates.NewTemplates() - e.Use(middleware.Logger()) - e.Use(middleware.Recover()) + s.echo.Renderer = templates.NewTemplates() + s.echo.Use(middleware.Logger()) + s.echo.Use(middleware.Recover()) db, query, err := internal.ConnectToDatabase(s.cfg.DatabasePath) if err != nil { @@ -51,7 +51,7 @@ func (s *Server) Start() error { h := handlers.NewBaseHandler(db, query, temporalClient, s.cfg) // Health - e.GET("/health", func(c echo.Context) error { + s.echo.GET("/health", func(c echo.Context) error { d, err := db.DB() if err != nil { return err @@ -65,16 +65,16 @@ func (s *Server) Start() error { }) // Server static files - stat := e.Group("/static") + stat := s.echo.Group("/static") stat.Use(middleware.StaticWithConfig(middleware.StaticConfig{ Filesystem: http.FS(static.Static), })) // Public - e.GET("", h.Index) + s.echo.GET("", h.Index) // Settings - settings := e.Group("/settings") + settings := s.echo.Group("/settings") settings.Use(h.Authenticated) settings.GET("", h.SettingsOverviewGET) settings.GET("/healthchecks", h.SettingsHealthchecksGET) @@ -89,19 +89,19 @@ func (s *Server) Start() error { settings.Match([]string{"GET", "HEAD", "POST", "PUT", "PATCH", "DELETE"}, "/temporal*", h.Temporal) // OAuth2 - oauth2 := e.Group("/oauth2") + oauth2 := s.echo.Group("/oauth2") oauth2.GET("/login", h.OAuth2LoginGET) oauth2.GET("/callback", h.OAuth2CallbackGET) oauth2.GET("/logout", h.OAuth2LogoutGET, h.Authenticated) // API - apiv1 := e.Group("/api/v1") + apiv1 := s.echo.Group("/api/v1") apiv1.Use(h.Authenticated) apiv1.GET("/workers/connect", h.ApiV1WorkersConnectGET) apiv1.POST("/healthcheck/:slug/history", h.ApiV1HealthchecksHistoryPOST) // Error handler - e.HTTPErrorHandler = func(err error, c echo.Context) { + s.echo.HTTPErrorHandler = func(err error, c echo.Context) { code := http.StatusInternalServerError if he, ok := err.(*echo.HTTPError); ok { code = he.Code @@ -114,10 +114,10 @@ func (s *Server) Start() error { _ = c.String(code, err.Error()) } - return e.Start(":" + s.cfg.Port) + return s.echo.Start(":" + s.cfg.Port) } func (s *Server) Stop() error { ctx := context.Background() - return s.server.Shutdown(ctx) + return s.echo.Shutdown(ctx) } diff --git a/pkg/worker/worker.go b/pkg/worker/worker.go index 7fa6a08..6575d20 100644 --- a/pkg/worker/worker.go +++ b/pkg/worker/worker.go @@ -5,11 +5,13 @@ import ( "io" "log" "net/http" + "time" "code.tjo.space/mentos1386/zdravko/internal/activities" "code.tjo.space/mentos1386/zdravko/internal/config" "code.tjo.space/mentos1386/zdravko/internal/temporal" "code.tjo.space/mentos1386/zdravko/internal/workflows" + "code.tjo.space/mentos1386/zdravko/pkg/retry" "github.com/pkg/errors" "go.temporal.io/sdk/worker" ) @@ -29,23 +31,25 @@ func getConnectionConfig(token string, apiUrl string) (*ConnectionConfig, error) } req.Header.Add("Authorization", "Bearer "+token) - res, err := http.DefaultClient.Do(req) - if err != nil { - return nil, errors.Wrap(err, "failed to connect to API") - } + return retry.Retry(10, 3*time.Second, func() (*ConnectionConfig, error) { + res, err := http.DefaultClient.Do(req) + if err != nil { + return nil, errors.Wrap(err, "failed to connect to API") + } - body, err := io.ReadAll(res.Body) - if err != nil { - return nil, errors.Wrap(err, "failed to read response body") - } + body, err := io.ReadAll(res.Body) + if err != nil { + return nil, errors.Wrap(err, "failed to read response body") + } - config := ConnectionConfig{} - err = json.Unmarshal(body, &config) - if err != nil { - return nil, errors.Wrap(err, "failed to unmarshal connection config") - } + config := ConnectionConfig{} + err = json.Unmarshal(body, &config) + if err != nil { + return nil, errors.Wrap(err, "failed to unmarshal connection config") + } - return &config, nil + return &config, nil + }) } type Worker struct { diff --git a/web/static/css/tailwind.css b/web/static/css/tailwind.css index e2fc23a..501cf0a 100644 --- a/web/static/css/tailwind.css +++ b/web/static/css/tailwind.css @@ -748,10 +748,18 @@ video { justify-content: center; } +.justify-between { + justify-content: space-between; +} + .gap-2 { gap: 0.5rem; } +.gap-4 { + gap: 1rem; +} + .gap-8 { gap: 2rem; } diff --git a/web/templates/pages/settings_healthchecks.tmpl b/web/templates/pages/settings_healthchecks.tmpl index 4ac3a79..fd0164a 100644 --- a/web/templates/pages/settings_healthchecks.tmpl +++ b/web/templates/pages/settings_healthchecks.tmpl @@ -1,6 +1,6 @@ {{define "settings"}} -{{ $description := "Healthchecks represent periodic checks of some HTTP or TCP service, to see if it's responding correctly to deterime if it's healthy or not." }} +{{ $description := "Healthchecks represent periodicly the k6 script, to see if the monitored service is healthy." }} {{ if eq .HealthchecksLength 0 }}
@@ -24,7 +24,7 @@ - @@ -66,9 +63,6 @@ {{range .WorkerGroups}} {{ . }} {{end}} - -
List of Healthchecks -
+

{{ $description }}

@@ -42,9 +42,6 @@
Worker Groups - Type - Status - HTTP OK diff --git a/web/templates/pages/settings_workers.tmpl b/web/templates/pages/settings_workers.tmpl index afa0863..e5c92fd 100644 --- a/web/templates/pages/settings_workers.tmpl +++ b/web/templates/pages/settings_workers.tmpl @@ -24,7 +24,7 @@
List of Workers -
+

{{ $description }}