Skip to content

Commit 2c19e72

Browse files
authored
fix: infinite loading (#54)
1 parent 7205165 commit 2c19e72

4 files changed

Lines changed: 60 additions & 51 deletions

File tree

cmd/serve.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,9 @@ func startup(scrollService *services.ScrollService, processLauncher *services.Pr
338338
}
339339
}
340340

341-
err = queueManager.QueueLockFile(callbacks)
341+
queueManager.RegisterCallbacks(callbacks)
342+
343+
err = queueManager.QueueLockFile()
342344
if err != nil {
343345
doneChan <- err
344346
return

go.mod

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module github.com/highcard-dev/daemon
22

33
go 1.22.0
44

5-
toolchain go1.22.5
5+
toolchain go1.22.8
66

77
require (
88
github.com/Masterminds/semver/v3 v3.2.1
@@ -75,12 +75,12 @@ require (
7575
github.com/valyala/tcplisten v1.0.0 // indirect
7676
github.com/yusufpapurcu/wmi v1.2.3 // indirect
7777
go.uber.org/multierr v1.11.0 // indirect
78-
golang.org/x/crypto v0.27.0 // indirect
79-
golang.org/x/net v0.29.0
80-
golang.org/x/sync v0.8.0 // indirect
81-
golang.org/x/sys v0.25.0 // indirect
82-
golang.org/x/text v0.18.0 // indirect
83-
golang.org/x/tools v0.25.0 // indirect
78+
golang.org/x/crypto v0.30.0 // indirect
79+
golang.org/x/net v0.32.0
80+
golang.org/x/sync v0.10.0 // indirect
81+
golang.org/x/sys v0.28.0 // indirect
82+
golang.org/x/text v0.21.0 // indirect
83+
golang.org/x/tools v0.28.0 // indirect
8484
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
8585
google.golang.org/grpc v1.65.0
8686
google.golang.org/protobuf v1.34.2
@@ -98,7 +98,7 @@ require (
9898
github.com/sirupsen/logrus v1.9.3 // indirect
9999
github.com/sourcegraph/conc v0.3.0 // indirect
100100
go.uber.org/atomic v1.9.0 // indirect
101-
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
101+
golang.org/x/exp v0.0.0-20241210194714-1829a127f884 // indirect
102102
)
103103

104104
require (

go.sum

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -260,16 +260,16 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
260260
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
261261
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
262262
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
263-
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
264-
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
265-
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk=
266-
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY=
263+
golang.org/x/crypto v0.30.0 h1:RwoQn3GkWiMkzlX562cLB7OxWvjH1L8xutO2WoJcRoY=
264+
golang.org/x/crypto v0.30.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
265+
golang.org/x/exp v0.0.0-20241210194714-1829a127f884 h1:Y/Mj/94zIQQGHVSv1tTtQBDaQaJe62U9bkDZKKyhPCU=
266+
golang.org/x/exp v0.0.0-20241210194714-1829a127f884/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c=
267267
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
268268
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
269269
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
270270
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
271-
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
272-
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
271+
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
272+
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
273273
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
274274
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
275275
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
@@ -278,14 +278,14 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
278278
golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
279279
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
280280
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
281-
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
282-
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
281+
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
282+
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
283283
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
284284
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
285285
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
286286
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
287-
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
288-
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
287+
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
288+
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
289289
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
290290
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
291291
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -306,8 +306,8 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
306306
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
307307
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
308308
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
309-
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
310-
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
309+
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
310+
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
311311
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
312312
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
313313
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
@@ -319,16 +319,16 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
319319
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
320320
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
321321
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
322-
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
323-
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
322+
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
323+
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
324324
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
325325
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
326326
golang.org/x/tools v0.0.0-20201022035929-9cf592e881e9/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
327327
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
328328
golang.org/x/tools v0.4.0/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ=
329329
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
330-
golang.org/x/tools v0.25.0 h1:oFU9pkj/iJgs+0DT+VMHrx+oBKs/LJMV+Uvg78sl+fE=
331-
golang.org/x/tools v0.25.0/go.mod h1:/vtpO8WL1N9cQC3FN5zPqb//fRXskFHbLKk4OW1Q7rg=
330+
golang.org/x/tools v0.28.0 h1:WuB6qZ4RPCQo5aP3WdKZS7i595EdWqWR8vqJTlwTVK8=
331+
golang.org/x/tools v0.28.0/go.mod h1:dcIOrVd3mfQKTgrDVQHqCPMWy6lnhfhtX3hLXYVLfRw=
332332
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
333333
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
334334
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

internal/core/services/queue_manager.go

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,31 @@ type AddItemOptions struct {
2020
}
2121

2222
type QueueManager struct {
23-
mu sync.Mutex
24-
runQueueMu sync.Mutex
25-
scrollService ports.ScrollServiceInterface
26-
processLauncher ports.ProcedureLauchnerInterface
27-
commandQueue map[string]*domain.QueueItem
28-
taskChan chan string
29-
taskDoneChan chan struct{}
30-
shutdownChan chan struct{}
31-
notifierChan []chan []string
23+
mu sync.Mutex
24+
runQueueMu sync.Mutex
25+
scrollService ports.ScrollServiceInterface
26+
processLauncher ports.ProcedureLauchnerInterface
27+
commandQueue map[string]*domain.QueueItem
28+
taskChan chan string
29+
taskDoneChan chan struct{}
30+
shutdownChan chan struct{}
31+
notifierChan []chan []string
32+
callbacksPostRun map[string]func()
3233
}
3334

3435
func NewQueueManager(
3536
scrollService ports.ScrollServiceInterface,
3637
processLauncher ports.ProcedureLauchnerInterface,
3738
) *QueueManager {
3839
return &QueueManager{
39-
scrollService: scrollService,
40-
processLauncher: processLauncher,
41-
commandQueue: make(map[string]*domain.QueueItem),
42-
taskChan: make(chan string),
43-
taskDoneChan: make(chan struct{}),
44-
shutdownChan: make(chan struct{}),
45-
notifierChan: make([]chan []string, 0),
40+
scrollService: scrollService,
41+
processLauncher: processLauncher,
42+
commandQueue: make(map[string]*domain.QueueItem),
43+
taskChan: make(chan string),
44+
taskDoneChan: make(chan struct{}),
45+
shutdownChan: make(chan struct{}),
46+
notifierChan: make([]chan []string, 0),
47+
callbacksPostRun: make(map[string]func()),
4648
}
4749
}
4850

@@ -164,16 +166,22 @@ func (sc *QueueManager) addQueueItem(cmd string, options AddItemOptions) error {
164166
return nil
165167
}
166168

167-
func (sc *QueueManager) QueueLockFile(callbacks map[string]func()) error {
169+
func (sc *QueueManager) RegisterCallbacks(callbacks map[string]func()) {
170+
sc.mu.Lock()
171+
defer sc.mu.Unlock()
172+
173+
for cmd, cb := range callbacks {
174+
sc.callbacksPostRun[cmd] = cb
175+
}
176+
}
177+
178+
func (sc *QueueManager) QueueLockFile() error {
168179
lock, err := sc.scrollService.GetLock()
169180

170181
if err != nil {
171182
return err
172183
}
173184
for cmd, status := range lock.Statuses {
174-
//finish directly
175-
fn := callbacks[cmd]
176-
177185
//convert legacy command names
178186
command, err := sc.scrollService.GetCommand(cmd)
179187
if err != nil {
@@ -184,10 +192,6 @@ func (sc *QueueManager) QueueLockFile(callbacks map[string]func()) error {
184192
//not sure if this can even happen, maybe on updates
185193
if command.Run != domain.RunModeRestart {
186194

187-
if fn != nil {
188-
fn()
189-
}
190-
191195
//TODO: use addQueueItem here
192196
sc.mu.Lock()
193197
sc.commandQueue[cmd] = &domain.QueueItem{
@@ -201,8 +205,7 @@ func (sc *QueueManager) QueueLockFile(callbacks map[string]func()) error {
201205
status.Status = domain.ScrollLockStatusWaiting
202206

203207
sc.addQueueItem(cmd, AddItemOptions{
204-
Remember: true,
205-
RunAfterExecution: fn,
208+
Remember: true,
206209
})
207210
}
208211

@@ -298,6 +301,10 @@ func (sc *QueueManager) RunQueue() {
298301
if i.RunAfterExecution != nil {
299302
i.RunAfterExecution()
300303
}
304+
if callback, ok := sc.callbacksPostRun[c]; ok && callback != nil {
305+
callback()
306+
}
307+
301308
sc.taskDoneChan <- struct{}{}
302309
}()
303310
err := sc.workItem(c)

0 commit comments

Comments
 (0)