Skip to content

Commit 6c7e38d

Browse files
committed
update valclient for stability
1 parent e440267 commit 6c7e38d

File tree

5 files changed

+19
-27
lines changed

5 files changed

+19
-27
lines changed

backend/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ module backend
22

33
go 1.25.1
44

5-
require github.com/truearken/valclient v0.1.1
5+
require github.com/truearken/valclient v0.1.3
66

77
require github.com/gorilla/websocket v1.5.3 // indirect

backend/go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ github.com/truearken/valclient v0.1.0 h1:xuJeqHfVy7LFDoiLQDKQOK1ACXmSx9iXHiwltIQ
44
github.com/truearken/valclient v0.1.0/go.mod h1:Vkw8qAcooztgWVj6AFf7pC+DzCYoCfrSK1wj0FncY4g=
55
github.com/truearken/valclient v0.1.1 h1:lhgg18HaVseJGIaxtI/XIL0IPPHeMlgg97qLwoOa/a8=
66
github.com/truearken/valclient v0.1.1/go.mod h1:Vkw8qAcooztgWVj6AFf7pC+DzCYoCfrSK1wj0FncY4g=
7+
github.com/truearken/valclient v0.1.2 h1:GJPNFPnIoye7T65pQQHKf7hTTFlitm4693OCFWtfqpQ=
8+
github.com/truearken/valclient v0.1.2/go.mod h1:Vkw8qAcooztgWVj6AFf7pC+DzCYoCfrSK1wj0FncY4g=
9+
github.com/truearken/valclient v0.1.3 h1:Uoo1EOThiOmgNcVjiAVq7ev9Yn0nHrGXn3GyW8Zol+U=
10+
github.com/truearken/valclient v0.1.3/go.mod h1:Vkw8qAcooztgWVj6AFf7pC+DzCYoCfrSK1wj0FncY4g=

backend/handlers/handlers.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,9 @@ func (h *Handler) SetTicker(ticker *tick.Ticker) {
2828
h.Ticker = ticker
2929
}
3030

31-
func (h *Handler) UpdateClient(newVal *valclient.ValClient) {
32-
h.mu.Lock()
33-
defer h.mu.Unlock()
34-
35-
h.Val = newVal
36-
37-
if h.Ticker != nil {
38-
h.Ticker.Stop()
39-
h.Ticker.Start()
40-
}
31+
func (h *Handler) RestartTicker(newVal *valclient.ValClient) {
32+
h.Ticker.Stop()
33+
h.Ticker.Start()
4134
}
4235

4336
type OwnedSkinsResponse struct {

backend/handlers/health.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
package handlers
22

33
import (
4-
"log/slog"
54
"net/http"
6-
7-
"github.com/truearken/valclient/valclient"
85
)
96

107
func (h *Handler) Health(w http.ResponseWriter, r *http.Request) {
118
if _, err := h.Val.GetHelp(); err != nil {
12-
newVal, _ := valclient.NewClient()
13-
if newVal != nil {
14-
slog.Info("valorant started, new client created")
15-
h.UpdateClient(newVal)
16-
} else {
17-
h.Ticker.Stop()
18-
}
19-
defer h.Val.Close()
20-
9+
h.Ticker.Stop()
2110
w.WriteHeader(http.StatusInternalServerError)
2211
return
2312
}
13+
h.Ticker.Start()
2414
w.WriteHeader(http.StatusOK)
2515
}

backend/tick/tick.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ func NewTicker(val *valclient.ValClient) *Ticker {
2929
}
3030

3131
func (t *Ticker) Start() {
32+
if t.running {
33+
return
34+
}
35+
3236
slog.Info("ticker started")
3337

3438
t.stopCh = make(chan struct{})
@@ -142,9 +146,10 @@ func (t *Ticker) Start() {
142146
}
143147

144148
func (t *Ticker) Stop() {
145-
if t.running {
146-
close(t.stopCh)
147-
t.running = false
148-
slog.Info("ticker stopped")
149+
if !t.running {
150+
return
149151
}
152+
close(t.stopCh)
153+
t.running = false
154+
slog.Info("ticker stopped")
150155
}

0 commit comments

Comments
 (0)