Skip to content

Commit

Permalink
fix issue where router was not reloading config if blocks change
Browse files Browse the repository at this point in the history
  • Loading branch information
maddalax committed Nov 27, 2024
1 parent 69a71af commit 736ca5b
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 21 deletions.
4 changes: 2 additions & 2 deletions app/domain_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ type Server struct {

func (server *Server) IsAccessible() bool {
now := time.Now()
// has sent an update in the last 10 seconds
return now.Sub(server.LastSeen) < time.Second*10
// has sent an update in the last 30 seconds
return now.Sub(server.LastSeen) < time.Second*30
}

func (server *Server) FormattedName() string {
Expand Down
8 changes: 8 additions & 0 deletions app/router_builder.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package app

import (
"dockside/app/logger"
"dockside/app/util/must"
"fmt"
"github.com/maddalax/htmgo/framework/service"
"github.com/maddalax/multiproxy"
"net/http"
"strings"
"time"
)

type ConfigBuilder struct {
Expand Down Expand Up @@ -45,6 +47,12 @@ func (b *ConfigBuilder) Append(resource *Resource, block *RouteBlock, lb *multip

// skip if server is not accessible
if !server.IsAccessible() {
logger.InfoWithFields("Server is not accessible", map[string]any{
"serverId": server.Id,
"lastCheck": server.LastSeen.String(),
"now": time.Now().String(),
"diff": time.Since(server.LastSeen).String(),
})
continue
}

Expand Down
5 changes: 5 additions & 0 deletions app/router_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ import (
"strings"
)

// ReloadConfig force reloads the router configuration
func ReloadConfig(locator *service.Locator) {
loadConfig(locator)
lb := GetServiceRegistry(locator).GetReverseProxy().lb
lb.ApplyStagedUpstreams()
}

// loadConfig calculates the new configuration for the router, but does not apply it,
// it must be applied by calling ApplyStagedUpstreams
func loadConfig(locator *service.Locator) {
builder := NewConfigBuilder(locator)
table, err := GetRouteTable(locator)
Expand Down
2 changes: 1 addition & 1 deletion app/ui/button.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func Button(props ButtonProps) *h.Element {
baseClasses,
sizeClasses[props.Size],
variantClasses[props.Variant],
h.Ternary(props.FullWidth, "w-full", ""),
h.Ternary(props.FullWidth, "w-full", "w-auto"),
props.Class,
)

Expand Down
6 changes: 0 additions & 6 deletions app/ui/sidebar.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,6 @@ func ResourceList(ctx *h.RequestContext) *h.Element {
Text: "+ New",
Href: urls.NewResourceUrl(),
}),

//h.A(
// h.Text("+ New"),
// h.Href(urls.NewResourceUrl()),
// h.Class("bg-slate-900 hover:bg-slate-800 text-white text-xs font-bold py-2 px-2 rounded"),
//),
),
h.Div(
h.Class("flex flex-col gap-2"),
Expand Down
15 changes: 9 additions & 6 deletions pages/resource/create/additional-fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ func AdditionalCreateResourceFields(ctx *h.RequestContext) *h.Partial {
return h.SwapPartial(
ctx,
h.Div(
h.Class("flex flex-col gap-4"),
h.Class("flex flex-col gap-2"),
h.Id("additional-create-resource-fields"),
AdditionalFieldsForDeploymentType(ctx, deploymentType),
EnvironmentVariables(ctx),
h.Div(
h.Id("submit-error"),
),
ui.SubmitButton(ui.ButtonProps{
Text: "Create Resource",
SubmittingText: "Validating...",
Class: "mt-4 w-full",
}),
h.Div(
ui.SubmitButton(ui.ButtonProps{
FullWidth: false,
Text: "Create Resource",
SubmittingText: "Validating...",
Class: "mt-4",
}),
),
),
)
}
6 changes: 3 additions & 3 deletions pages/resource/create/create-form.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ func DeploymentChoiceSelector() *h.Element {
h.Class("sr-only"),
),
h.Div(
h.Class("max-w-[40%]"),
h.Class("max-w-[250px]"),
DockerFileChoice(),
),
h.Div(
h.Class("max-w-[40%]"),
h.Class("max-w-[250px]"),
DockerRegistryChoice(),
),
),
Expand Down Expand Up @@ -49,7 +49,7 @@ func DockerRegistryChoice() *h.Element {
t := "docker_registry"
return ui.ChoiceCard(ui.ChoiceCardProps{
Title: "Docker Registry",
Description: "Run your application from an existing Docker image in a registry",
Description: "Run your application from an existing Docker image",
Icon: icons.DockerIconBlack(),
InputName: "deployment-type",
InputValue: t,
Expand Down
2 changes: 0 additions & 2 deletions pages/resource/create/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ func EnvironmentVariables(ctx *h.RequestContext) *h.Element {
},
Id: "environment-variables",
OnAdd: func(data ws.HandlerData) {
//ws.BroadcastServerSideEvent("increment", map[string]any{})
},
OnRemove: func(data ws.HandlerData, index int) {
//ws.BroadcastServerSideEvent("decrement", map[string]any{})
},
AddButton: h.Button(
h.Type("button"),
Expand Down
2 changes: 1 addition & 1 deletion pages/routing/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func Setup(ctx *h.RequestContext) *h.Page {
h.Class("text-xl font-bold"),
),
h.Div(
ui.PrimaryButton(ui.ButtonProps{
ui.SubmitButton(ui.ButtonProps{
Text: "Save Changes",
SubmittingText: "Saving...",
}),
Expand Down

0 comments on commit 736ca5b

Please sign in to comment.