Skip to content

Commit 2e56e93

Browse files
committed
fix: ensure foreground tasks stop immediately when scheduler stops
1 parent f591cca commit 2e56e93

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

backend/app/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
)
1717

1818
// Define version constant
19-
const Version = "1.2.4"
19+
const Version = "1.2.6"
2020

2121
// var wailsContext *context.Context
2222

backend/model/scheduler.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,17 @@ func GetScheduler() *Scheduler {
8787
return scheduler
8888
}
8989

90+
func (s *Scheduler) TriggerCloseFunc() {
91+
if s.AutoClose && s.CloseFunc != nil {
92+
s.CloseFunc()
93+
}
94+
}
95+
9096
// Stop halts the scheduler
9197
func (s *Scheduler) Stop() {
9298
s.mu.Lock()
9399
s.IsRunning = false
94100
s.mu.Unlock()
95-
96-
if s.AutoClose && s.CloseFunc != nil {
97-
s.CloseFunc()
98-
}
99101
}
100102

101103
// Start activates the scheduler

backend/service/scheduler.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ func (s *SchedulerService) StartAll() {
348348
wg.Wait()
349349
utils.Logger.Info("All tasks completed, stopping scheduler")
350350
scheduler.Stop()
351+
scheduler.TriggerCloseFunc()
351352
s.wsService.BroadcastState("", model.StatusPending)
352353
}()
353354
}
@@ -448,30 +449,29 @@ func (s *SchedulerService) runForegroundTasks(tasks []string) {
448449
// StopAll stops the scheduler and all tasks
449450
func (s *SchedulerService) StopAll() {
450451
utils.Logger.Info("Stopping all running instances...")
452+
scheduler := model.GetScheduler()
453+
if !scheduler.IsRunning {
454+
utils.Logger.Info("Scheduler is not running")
455+
return
456+
}
457+
458+
// Stop the scheduler
459+
scheduler.Stop()
460+
s.wsService.BroadcastState("", model.StatusPending)
451461

452462
// Get all instances
453463
var instances []model.InstanceInfo
454464
if err := model.GetAllInstances(&instances); err != nil {
455465
utils.Logger.Error("Failed to get all instances:", err)
456466
return
457467
}
458-
459468
// Stop all running instances
460-
scheduler := model.GetScheduler()
461469
for _, ist := range instances {
462470
tm := scheduler.GetTaskManager(ist.Name)
463471
if tm != nil && tm.Status == model.StatusRunning {
464472
s.stopOne(ist.Name, nil)
465473
}
466474
}
467475

468-
// Prevent loop calls in CloseApp
469-
if !scheduler.IsRunning {
470-
utils.Logger.Info("Scheduler is not running")
471-
return
472-
}
473-
474-
// Stop the scheduler
475-
scheduler.Stop()
476-
s.wsService.BroadcastState("", model.StatusPending)
476+
scheduler.TriggerCloseFunc()
477477
}

wails.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"frontend:dev:watcher": "npm run dev",
88
"frontend:dev:serverUrl": "http://localhost:33204",
99
"info": {
10-
"productVersion": "1.2.4",
10+
"productVersion": "1.2.6",
1111
"copyright": "Copyright © 2024 DaCapo Aues6uen11Z",
1212
"comments": "A graphical script manager driven by configuration files"
1313
}

0 commit comments

Comments
 (0)