Skip to content

Commit e3cb2f6

Browse files
committed
FEAT: autoHistoryExit
1 parent e712662 commit e3cb2f6

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ func defaultConfiguration() configuration {
163163
// History
164164
HistoryMaxJobs: defConfig_HistoryMaxJobs,
165165
AutoHistory: false,
166+
AutoHistoryExit: false,
166167
AutoHistoryBefore: "",
167168
AutoHistorySince: "",
168169
SendHistoryStatus: true,
@@ -297,6 +298,7 @@ type configuration struct {
297298
// History
298299
HistoryMaxJobs int `json:"historyMaxJobs" yaml:"historyMaxJobs"`
299300
AutoHistory bool `json:"autoHistory" yaml:"autoHistory"`
301+
AutoHistoryExit bool `json:"autoHistoryExit" yaml:"autoHistoryExit"`
300302
AutoHistoryBefore string `json:"autoHistoryBefore" yaml:"autoHistoryBefore"`
301303
AutoHistorySince string `json:"autoHistorySince" yaml:"autoHistorySince"`
302304
SendAutoHistoryStatus bool `json:"sendAutoHistoryStatus" yaml:"sendAutoHistoryStatus"`

main.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ import (
2525

2626
var (
2727
// General
28-
err error
29-
loop chan os.Signal
30-
mainWg sync.WaitGroup
31-
startTime time.Time
32-
ddgUpdateAvailable bool = false
28+
err error
29+
loop chan os.Signal
30+
mainWg sync.WaitGroup
31+
startTime time.Time
32+
ddgUpdateAvailable bool = false
33+
autoHistoryInitiated bool = false
3334

3435
// Downloads
3536
timeLastUpdated time.Time
@@ -147,6 +148,7 @@ func main() {
147148
//#region [Loops] History Job Processing
148149
go func() {
149150
for {
151+
newJobCount := 0
150152
// Empty Local Cache
151153
nhistoryJobCnt,
152154
nhistoryJobCntWaiting,
@@ -178,15 +180,14 @@ func main() {
178180
if nhistoryJobCntRunning < config.HistoryMaxJobs || config.HistoryMaxJobs < 1 {
179181
openSlots := config.HistoryMaxJobs - nhistoryJobCntRunning
180182
newJobs := make([]historyJob, openSlots)
181-
filledSlots := 0
182183
// Find Jobs
183184
for pair := historyJobs.Oldest(); pair != nil; pair = pair.Next() {
184-
if filledSlots == openSlots {
185+
if newJobCount == openSlots {
185186
break
186187
}
187188
if pair.Value.Status == historyStatusWaiting {
188189
newJobs = append(newJobs, pair.Value)
189-
filledSlots++
190+
newJobCount++
190191
}
191192
}
192193
// Start Jobs
@@ -210,6 +211,13 @@ func main() {
210211

211212
// Wait before checking again
212213
time.Sleep(time.Duration(config.HistoryManagerRate) * time.Second)
214+
215+
// Auto Exit
216+
if config.AutoHistoryExit && autoHistoryInitiated &&
217+
historyJobs.Len() > 0 && newJobCount == 0 && historyJobCntWaiting == 0 && historyJobCntRunning == 0 {
218+
log.Println(lg("History", "", color.HiCyanString, "Exiting due to auto history completion..."))
219+
properExit()
220+
}
213221
}
214222
}()
215223
//#endregion
@@ -294,6 +302,7 @@ func main() {
294302
//TODO: signals for this and typical history cmd??
295303
}
296304
}
305+
autoHistoryInitiated = true
297306
if len(autoHistoryChannels) > 0 {
298307
log.Println(lg("History", "Autorun", color.HiYellowString,
299308
"History Autoruns completed (for %d channel%s)",

0 commit comments

Comments
 (0)