@@ -25,11 +25,12 @@ import (
25
25
26
26
var (
27
27
// 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
33
34
34
35
// Downloads
35
36
timeLastUpdated time.Time
@@ -147,6 +148,7 @@ func main() {
147
148
//#region [Loops] History Job Processing
148
149
go func () {
149
150
for {
151
+ newJobCount := 0
150
152
// Empty Local Cache
151
153
nhistoryJobCnt ,
152
154
nhistoryJobCntWaiting ,
@@ -178,15 +180,14 @@ func main() {
178
180
if nhistoryJobCntRunning < config .HistoryMaxJobs || config .HistoryMaxJobs < 1 {
179
181
openSlots := config .HistoryMaxJobs - nhistoryJobCntRunning
180
182
newJobs := make ([]historyJob , openSlots )
181
- filledSlots := 0
182
183
// Find Jobs
183
184
for pair := historyJobs .Oldest (); pair != nil ; pair = pair .Next () {
184
- if filledSlots == openSlots {
185
+ if newJobCount == openSlots {
185
186
break
186
187
}
187
188
if pair .Value .Status == historyStatusWaiting {
188
189
newJobs = append (newJobs , pair .Value )
189
- filledSlots ++
190
+ newJobCount ++
190
191
}
191
192
}
192
193
// Start Jobs
@@ -210,6 +211,13 @@ func main() {
210
211
211
212
// Wait before checking again
212
213
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
+ }
213
221
}
214
222
}()
215
223
//#endregion
@@ -294,6 +302,7 @@ func main() {
294
302
//TODO: signals for this and typical history cmd??
295
303
}
296
304
}
305
+ autoHistoryInitiated = true
297
306
if len (autoHistoryChannels ) > 0 {
298
307
log .Println (lg ("History" , "Autorun" , color .HiYellowString ,
299
308
"History Autoruns completed (for %d channel%s)" ,
0 commit comments