mirror of
https://github.com/mentos1386/zdravko.git
synced 2025-04-09 22:57:55 +00:00
fix: worker retry and fly new database
This commit is contained in:
parent
c862660e7d
commit
f8c8e381c1
6 changed files with 48 additions and 39 deletions
deploy
pkg
web
|
@ -16,6 +16,9 @@ primary_region = 'waw'
|
||||||
ROOT_URL = 'https://zdravko.mnts.dev'
|
ROOT_URL = 'https://zdravko.mnts.dev'
|
||||||
TEMPORAL_SERVER_HOST = 'server.process.zdravko.internal:7233'
|
TEMPORAL_SERVER_HOST = 'server.process.zdravko.internal:7233'
|
||||||
|
|
||||||
|
TEMPORAL_DATABASE_PATH = '/data/temporal-1.db'
|
||||||
|
DATABASE_PATH = '/data/zdravko-1.db'
|
||||||
|
|
||||||
[processes]
|
[processes]
|
||||||
server = '--temporal --server'
|
server = '--temporal --server'
|
||||||
worker = '--worker'
|
worker = '--worker'
|
||||||
|
|
|
@ -16,13 +16,14 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
server *http.Server
|
echo *echo.Echo
|
||||||
cfg *config.ServerConfig
|
cfg *config.ServerConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer(cfg *config.ServerConfig) (*Server, error) {
|
func NewServer(cfg *config.ServerConfig) (*Server, error) {
|
||||||
return &Server{
|
return &Server{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
|
echo: echo.New(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,10 +32,9 @@ func (s *Server) Name() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Start() error {
|
func (s *Server) Start() error {
|
||||||
e := echo.New()
|
s.echo.Renderer = templates.NewTemplates()
|
||||||
e.Renderer = templates.NewTemplates()
|
s.echo.Use(middleware.Logger())
|
||||||
e.Use(middleware.Logger())
|
s.echo.Use(middleware.Recover())
|
||||||
e.Use(middleware.Recover())
|
|
||||||
|
|
||||||
db, query, err := internal.ConnectToDatabase(s.cfg.DatabasePath)
|
db, query, err := internal.ConnectToDatabase(s.cfg.DatabasePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -51,7 +51,7 @@ func (s *Server) Start() error {
|
||||||
h := handlers.NewBaseHandler(db, query, temporalClient, s.cfg)
|
h := handlers.NewBaseHandler(db, query, temporalClient, s.cfg)
|
||||||
|
|
||||||
// Health
|
// Health
|
||||||
e.GET("/health", func(c echo.Context) error {
|
s.echo.GET("/health", func(c echo.Context) error {
|
||||||
d, err := db.DB()
|
d, err := db.DB()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -65,16 +65,16 @@ func (s *Server) Start() error {
|
||||||
})
|
})
|
||||||
|
|
||||||
// Server static files
|
// Server static files
|
||||||
stat := e.Group("/static")
|
stat := s.echo.Group("/static")
|
||||||
stat.Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
stat.Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
||||||
Filesystem: http.FS(static.Static),
|
Filesystem: http.FS(static.Static),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// Public
|
// Public
|
||||||
e.GET("", h.Index)
|
s.echo.GET("", h.Index)
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
settings := e.Group("/settings")
|
settings := s.echo.Group("/settings")
|
||||||
settings.Use(h.Authenticated)
|
settings.Use(h.Authenticated)
|
||||||
settings.GET("", h.SettingsOverviewGET)
|
settings.GET("", h.SettingsOverviewGET)
|
||||||
settings.GET("/healthchecks", h.SettingsHealthchecksGET)
|
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)
|
settings.Match([]string{"GET", "HEAD", "POST", "PUT", "PATCH", "DELETE"}, "/temporal*", h.Temporal)
|
||||||
|
|
||||||
// OAuth2
|
// OAuth2
|
||||||
oauth2 := e.Group("/oauth2")
|
oauth2 := s.echo.Group("/oauth2")
|
||||||
oauth2.GET("/login", h.OAuth2LoginGET)
|
oauth2.GET("/login", h.OAuth2LoginGET)
|
||||||
oauth2.GET("/callback", h.OAuth2CallbackGET)
|
oauth2.GET("/callback", h.OAuth2CallbackGET)
|
||||||
oauth2.GET("/logout", h.OAuth2LogoutGET, h.Authenticated)
|
oauth2.GET("/logout", h.OAuth2LogoutGET, h.Authenticated)
|
||||||
|
|
||||||
// API
|
// API
|
||||||
apiv1 := e.Group("/api/v1")
|
apiv1 := s.echo.Group("/api/v1")
|
||||||
apiv1.Use(h.Authenticated)
|
apiv1.Use(h.Authenticated)
|
||||||
apiv1.GET("/workers/connect", h.ApiV1WorkersConnectGET)
|
apiv1.GET("/workers/connect", h.ApiV1WorkersConnectGET)
|
||||||
apiv1.POST("/healthcheck/:slug/history", h.ApiV1HealthchecksHistoryPOST)
|
apiv1.POST("/healthcheck/:slug/history", h.ApiV1HealthchecksHistoryPOST)
|
||||||
|
|
||||||
// Error handler
|
// Error handler
|
||||||
e.HTTPErrorHandler = func(err error, c echo.Context) {
|
s.echo.HTTPErrorHandler = func(err error, c echo.Context) {
|
||||||
code := http.StatusInternalServerError
|
code := http.StatusInternalServerError
|
||||||
if he, ok := err.(*echo.HTTPError); ok {
|
if he, ok := err.(*echo.HTTPError); ok {
|
||||||
code = he.Code
|
code = he.Code
|
||||||
|
@ -114,10 +114,10 @@ func (s *Server) Start() error {
|
||||||
_ = c.String(code, err.Error())
|
_ = c.String(code, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
return e.Start(":" + s.cfg.Port)
|
return s.echo.Start(":" + s.cfg.Port)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Stop() error {
|
func (s *Server) Stop() error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
return s.server.Shutdown(ctx)
|
return s.echo.Shutdown(ctx)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,13 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.tjo.space/mentos1386/zdravko/internal/activities"
|
"code.tjo.space/mentos1386/zdravko/internal/activities"
|
||||||
"code.tjo.space/mentos1386/zdravko/internal/config"
|
"code.tjo.space/mentos1386/zdravko/internal/config"
|
||||||
"code.tjo.space/mentos1386/zdravko/internal/temporal"
|
"code.tjo.space/mentos1386/zdravko/internal/temporal"
|
||||||
"code.tjo.space/mentos1386/zdravko/internal/workflows"
|
"code.tjo.space/mentos1386/zdravko/internal/workflows"
|
||||||
|
"code.tjo.space/mentos1386/zdravko/pkg/retry"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"go.temporal.io/sdk/worker"
|
"go.temporal.io/sdk/worker"
|
||||||
)
|
)
|
||||||
|
@ -29,6 +31,7 @@ func getConnectionConfig(token string, apiUrl string) (*ConnectionConfig, error)
|
||||||
}
|
}
|
||||||
req.Header.Add("Authorization", "Bearer "+token)
|
req.Header.Add("Authorization", "Bearer "+token)
|
||||||
|
|
||||||
|
return retry.Retry(10, 3*time.Second, func() (*ConnectionConfig, error) {
|
||||||
res, err := http.DefaultClient.Do(req)
|
res, err := http.DefaultClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to connect to API")
|
return nil, errors.Wrap(err, "failed to connect to API")
|
||||||
|
@ -46,6 +49,7 @@ func getConnectionConfig(token string, apiUrl string) (*ConnectionConfig, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &config, nil
|
return &config, nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type Worker struct {
|
type Worker struct {
|
||||||
|
|
|
@ -748,10 +748,18 @@ video {
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.justify-between {
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
.gap-2 {
|
.gap-2 {
|
||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.gap-4 {
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
.gap-8 {
|
.gap-8 {
|
||||||
gap: 2rem;
|
gap: 2rem;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{{define "settings"}}
|
{{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 }}
|
{{ if eq .HealthchecksLength 0 }}
|
||||||
<section>
|
<section>
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
<table class="w-full text-sm text-left rtl:text-right text-gray-500">
|
<table class="w-full text-sm text-left rtl:text-right text-gray-500">
|
||||||
<caption class="p-5 text-lg font-semibold text-left rtl:text-right text-gray-900 bg-white">
|
<caption class="p-5 text-lg font-semibold text-left rtl:text-right text-gray-900 bg-white">
|
||||||
List of Healthchecks
|
List of Healthchecks
|
||||||
<div class="mt-1 flex">
|
<div class="mt-1 gap-4 flex justify-between">
|
||||||
<p class="mt-1 text-sm font-normal text-gray-500">
|
<p class="mt-1 text-sm font-normal text-gray-500">
|
||||||
{{ $description }}
|
{{ $description }}
|
||||||
</p>
|
</p>
|
||||||
|
@ -42,9 +42,6 @@
|
||||||
<th scope="col" class="px-6 py-3">
|
<th scope="col" class="px-6 py-3">
|
||||||
Worker Groups
|
Worker Groups
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" class="px-6 py-3">
|
|
||||||
Type
|
|
||||||
</th>
|
|
||||||
<th scope="col" class="px-6 py-3">
|
<th scope="col" class="px-6 py-3">
|
||||||
Status
|
Status
|
||||||
</th>
|
</th>
|
||||||
|
@ -66,9 +63,6 @@
|
||||||
{{range .WorkerGroups}}
|
{{range .WorkerGroups}}
|
||||||
{{ . }}
|
{{ . }}
|
||||||
{{end}}
|
{{end}}
|
||||||
</td>
|
|
||||||
<td class="px-6 py-4">
|
|
||||||
HTTP
|
|
||||||
</td>
|
</td>
|
||||||
<td class="px-6 py-4">
|
<td class="px-6 py-4">
|
||||||
OK
|
OK
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
<table class="w-full text-sm text-left rtl:text-right text-gray-500">
|
<table class="w-full text-sm text-left rtl:text-right text-gray-500">
|
||||||
<caption class="p-5 text-lg font-semibold text-left rtl:text-right text-gray-900 bg-white">
|
<caption class="p-5 text-lg font-semibold text-left rtl:text-right text-gray-900 bg-white">
|
||||||
List of Workers
|
List of Workers
|
||||||
<div class="mt-1 flex">
|
<div class="mt-1 gap-4 flex justify-between">
|
||||||
<p class="mt-1 text-sm font-normal text-gray-500">
|
<p class="mt-1 text-sm font-normal text-gray-500">
|
||||||
{{ $description }}
|
{{ $description }}
|
||||||
</p>
|
</p>
|
||||||
|
|
Loading…
Reference in a new issue