mirror of
https://github.com/get-got/discord-downloader-go.git
synced 2025-12-01 12:07:15 +00:00
FEAT: autoHistoryExit
This commit is contained in:
@ -163,6 +163,7 @@ func defaultConfiguration() configuration {
|
||||
// History
|
||||
HistoryMaxJobs: defConfig_HistoryMaxJobs,
|
||||
AutoHistory: false,
|
||||
AutoHistoryExit: false,
|
||||
AutoHistoryBefore: "",
|
||||
AutoHistorySince: "",
|
||||
SendHistoryStatus: true,
|
||||
@ -297,6 +298,7 @@ type configuration struct {
|
||||
// History
|
||||
HistoryMaxJobs int `json:"historyMaxJobs" yaml:"historyMaxJobs"`
|
||||
AutoHistory bool `json:"autoHistory" yaml:"autoHistory"`
|
||||
AutoHistoryExit bool `json:"autoHistoryExit" yaml:"autoHistoryExit"`
|
||||
AutoHistoryBefore string `json:"autoHistoryBefore" yaml:"autoHistoryBefore"`
|
||||
AutoHistorySince string `json:"autoHistorySince" yaml:"autoHistorySince"`
|
||||
SendAutoHistoryStatus bool `json:"sendAutoHistoryStatus" yaml:"sendAutoHistoryStatus"`
|
||||
|
||||
25
main.go
25
main.go
@ -25,11 +25,12 @@ import (
|
||||
|
||||
var (
|
||||
// General
|
||||
err error
|
||||
loop chan os.Signal
|
||||
mainWg sync.WaitGroup
|
||||
startTime time.Time
|
||||
ddgUpdateAvailable bool = false
|
||||
err error
|
||||
loop chan os.Signal
|
||||
mainWg sync.WaitGroup
|
||||
startTime time.Time
|
||||
ddgUpdateAvailable bool = false
|
||||
autoHistoryInitiated bool = false
|
||||
|
||||
// Downloads
|
||||
timeLastUpdated time.Time
|
||||
@ -147,6 +148,7 @@ func main() {
|
||||
//#region [Loops] History Job Processing
|
||||
go func() {
|
||||
for {
|
||||
newJobCount := 0
|
||||
// Empty Local Cache
|
||||
nhistoryJobCnt,
|
||||
nhistoryJobCntWaiting,
|
||||
@ -178,15 +180,14 @@ func main() {
|
||||
if nhistoryJobCntRunning < config.HistoryMaxJobs || config.HistoryMaxJobs < 1 {
|
||||
openSlots := config.HistoryMaxJobs - nhistoryJobCntRunning
|
||||
newJobs := make([]historyJob, openSlots)
|
||||
filledSlots := 0
|
||||
// Find Jobs
|
||||
for pair := historyJobs.Oldest(); pair != nil; pair = pair.Next() {
|
||||
if filledSlots == openSlots {
|
||||
if newJobCount == openSlots {
|
||||
break
|
||||
}
|
||||
if pair.Value.Status == historyStatusWaiting {
|
||||
newJobs = append(newJobs, pair.Value)
|
||||
filledSlots++
|
||||
newJobCount++
|
||||
}
|
||||
}
|
||||
// Start Jobs
|
||||
@ -210,6 +211,13 @@ func main() {
|
||||
|
||||
// Wait before checking again
|
||||
time.Sleep(time.Duration(config.HistoryManagerRate) * time.Second)
|
||||
|
||||
// Auto Exit
|
||||
if config.AutoHistoryExit && autoHistoryInitiated &&
|
||||
historyJobs.Len() > 0 && newJobCount == 0 && historyJobCntWaiting == 0 && historyJobCntRunning == 0 {
|
||||
log.Println(lg("History", "", color.HiCyanString, "Exiting due to auto history completion..."))
|
||||
properExit()
|
||||
}
|
||||
}
|
||||
}()
|
||||
//#endregion
|
||||
@ -294,6 +302,7 @@ func main() {
|
||||
//TODO: signals for this and typical history cmd??
|
||||
}
|
||||
}
|
||||
autoHistoryInitiated = true
|
||||
if len(autoHistoryChannels) > 0 {
|
||||
log.Println(lg("History", "Autorun", color.HiYellowString,
|
||||
"History Autoruns completed (for %d channel%s)",
|
||||
|
||||
Reference in New Issue
Block a user