Skip to content

Commit

Permalink
Save state snapshot after commands
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmcconnell committed Aug 1, 2024
1 parent 0adb7fe commit 3b1c3d4
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions internal/server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ func (r *Router) SetServiceTarget(name string, host string, targetURL string,
options ServiceOptions, targetOptions TargetOptions,
deployTimeout time.Duration, drainTimeout time.Duration) error {

defer r.saveStateSnapshot()

slog.Info("Deploying", "service", name, "host", host, "target", targetURL, "tls", options.RequireTLS())

target, err := NewTarget(targetURL, targetOptions)
Expand All @@ -107,11 +109,12 @@ func (r *Router) SetServiceTarget(name string, host string, targetURL string,
}

slog.Info("Deployed", "service", name, "host", host, "target", targetURL)

return r.saveStateSnapshot()
return nil
}

func (r *Router) SetRolloutTarget(name string, targetURL string, deployTimeout time.Duration, drainTimeout time.Duration) error {
defer r.saveStateSnapshot()

slog.Info("Deploying for rollout", "service", name, "target", targetURL)

service := r.serviceForName(name, true)
Expand All @@ -134,11 +137,12 @@ func (r *Router) SetRolloutTarget(name string, targetURL string, deployTimeout t
service.SetTarget(TargetSlotRollout, target, drainTimeout)

slog.Info("Deployed for rollout", "service", name, "target", targetURL)

return r.saveStateSnapshot()
return nil
}

func (r *Router) SetRolloutSplit(name string, percent int, allowList []string) error {
defer r.saveStateSnapshot()

service := r.serviceForName(name, true)
if service == nil {
return ErrorServiceNotFound
Expand All @@ -148,6 +152,8 @@ func (r *Router) SetRolloutSplit(name string, percent int, allowList []string) e
}

func (r *Router) StopRollout(name string) error {
defer r.saveStateSnapshot()

service := r.serviceForName(name, true)
if service == nil {
return ErrorServiceNotFound
Expand All @@ -157,6 +163,8 @@ func (r *Router) StopRollout(name string) error {
}

func (r *Router) RemoveService(name string) error {
defer r.saveStateSnapshot()

err := r.withWriteLock(func() error {
service := r.serviceForName(name, false)
if service == nil {
Expand All @@ -173,10 +181,12 @@ func (r *Router) RemoveService(name string) error {
return err
}

return r.saveStateSnapshot()
return nil
}

func (r *Router) PauseService(name string, drainTimeout time.Duration, pauseTimeout time.Duration) error {
defer r.saveStateSnapshot()

service := r.serviceForName(name, true)
if service == nil {
return ErrorServiceNotFound
Expand All @@ -186,6 +196,8 @@ func (r *Router) PauseService(name string, drainTimeout time.Duration, pauseTime
}

func (r *Router) StopService(name string, drainTimeout time.Duration) error {
defer r.saveStateSnapshot()

service := r.serviceForName(name, true)
if service == nil {
return ErrorServiceNotFound
Expand All @@ -195,6 +207,8 @@ func (r *Router) StopService(name string, drainTimeout time.Duration) error {
}

func (r *Router) ResumeService(name string) error {
defer r.saveStateSnapshot()

service := r.serviceForName(name, true)
if service == nil {
return ErrorServiceNotFound
Expand Down

0 comments on commit 3b1c3d4

Please sign in to comment.