mirror of
https://github.com/stashapp/stash.git
synced 2025-12-16 05:13:46 +01:00
Add timeout to neededGenerate function (#324)
* Add timeout to neededGenerate function * * verbose and cosmetic fixes
This commit is contained in:
parent
d2e67fdb31
commit
fed7311d9c
1 changed files with 26 additions and 2 deletions
|
|
@ -165,8 +165,12 @@ func (s *singleton) Generate(sprites bool, previews bool, markers bool, transcod
|
|||
return
|
||||
}
|
||||
totalsNeeded := s.neededGenerate(scenes, sprites, previews, markers, transcodes)
|
||||
logger.Infof("Generating %d sprites %d previews %d markers %d transcodes", totalsNeeded.sprites, totalsNeeded.previews, totalsNeeded.markers, totalsNeeded.transcodes)
|
||||
|
||||
if totalsNeeded == nil {
|
||||
logger.Infof("Taking too long to count content. Skipping...")
|
||||
logger.Infof("Generating content")
|
||||
} else {
|
||||
logger.Infof("Generating %d sprites %d previews %d markers %d transcodes", totalsNeeded.sprites, totalsNeeded.previews, totalsNeeded.markers, totalsNeeded.transcodes)
|
||||
}
|
||||
for i, scene := range scenes {
|
||||
s.Status.setProgress(i, total)
|
||||
if s.Status.stopping {
|
||||
|
|
@ -208,6 +212,7 @@ func (s *singleton) Generate(sprites bool, previews bool, markers bool, transcod
|
|||
|
||||
wg.Wait()
|
||||
}
|
||||
logger.Infof("Generate finished")
|
||||
}()
|
||||
}
|
||||
|
||||
|
|
@ -461,6 +466,18 @@ type totalsGenerate struct {
|
|||
func (s *singleton) neededGenerate(scenes []*models.Scene, sprites, previews, markers, transcodes bool) *totalsGenerate {
|
||||
|
||||
var totals totalsGenerate
|
||||
const timeoutSecs = 90 * time.Second
|
||||
|
||||
// create a control channel through which to signal the counting loop when the timeout is reached
|
||||
chTimeout := make(chan struct{})
|
||||
|
||||
//run the timeout function in a separate thread
|
||||
go func() {
|
||||
time.Sleep(timeoutSecs)
|
||||
chTimeout <- struct{}{}
|
||||
}()
|
||||
|
||||
logger.Infof("Counting content to generate...")
|
||||
for _, scene := range scenes {
|
||||
if scene != nil {
|
||||
if sprites {
|
||||
|
|
@ -489,6 +506,13 @@ func (s *singleton) neededGenerate(scenes []*models.Scene, sprites, previews, ma
|
|||
}
|
||||
}
|
||||
}
|
||||
//check for timeout
|
||||
select {
|
||||
case <-chTimeout:
|
||||
return nil
|
||||
default:
|
||||
}
|
||||
|
||||
}
|
||||
return &totals
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue