mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
Reorder waitgroup completion (#1748)
Rather than passing a pointer to a waitgroup into task.Start(..) functions, handle the waitgroup.Done() at the callsite. This makes waitgroup handling local to its definition rather than it being spread out over multiple files. Tasks now simply execute, and the policy of waiting on them is handled by the caller.
This commit is contained in:
@@ -82,9 +82,6 @@ func (s *singleton) Import(ctx context.Context) (int, error) {
|
||||
}
|
||||
|
||||
j := job.MakeJobExec(func(ctx context.Context, progress *job.Progress) {
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
|
||||
task := ImportTask{
|
||||
txnManager: s.TxnManager,
|
||||
BaseDir: metadataPath,
|
||||
@@ -93,7 +90,7 @@ func (s *singleton) Import(ctx context.Context) (int, error) {
|
||||
MissingRefBehaviour: models.ImportMissingRefEnumFail,
|
||||
fileNamingAlgorithm: config.GetVideoFileNamingAlgorithm(),
|
||||
}
|
||||
task.Start(&wg)
|
||||
task.Start()
|
||||
})
|
||||
|
||||
return s.JobManager.Add(ctx, "Importing...", j), nil
|
||||
@@ -125,7 +122,8 @@ func (s *singleton) RunSingleTask(ctx context.Context, t Task) int {
|
||||
wg.Add(1)
|
||||
|
||||
j := job.MakeJobExec(func(ctx context.Context, progress *job.Progress) {
|
||||
t.Start(&wg)
|
||||
t.Start()
|
||||
wg.Done()
|
||||
})
|
||||
|
||||
return s.JobManager.Add(ctx, t.GetDescription(), j)
|
||||
@@ -280,7 +278,8 @@ func (s *singleton) Generate(ctx context.Context, input models.GenerateMetadataI
|
||||
}
|
||||
wg.Add()
|
||||
go progress.ExecuteTask(fmt.Sprintf("Generating sprites for %s", scene.Path), func() {
|
||||
task.Start(&wg)
|
||||
task.Start()
|
||||
wg.Done()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -294,7 +293,8 @@ func (s *singleton) Generate(ctx context.Context, input models.GenerateMetadataI
|
||||
}
|
||||
wg.Add()
|
||||
go progress.ExecuteTask(fmt.Sprintf("Generating preview for %s", scene.Path), func() {
|
||||
task.Start(&wg)
|
||||
task.Start()
|
||||
wg.Done()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -309,7 +309,8 @@ func (s *singleton) Generate(ctx context.Context, input models.GenerateMetadataI
|
||||
Screenshot: input.MarkerScreenshots,
|
||||
}
|
||||
go progress.ExecuteTask(fmt.Sprintf("Generating markers for %s", scene.Path), func() {
|
||||
task.Start(&wg)
|
||||
task.Start()
|
||||
wg.Done()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -321,7 +322,8 @@ func (s *singleton) Generate(ctx context.Context, input models.GenerateMetadataI
|
||||
fileNamingAlgorithm: fileNamingAlgo,
|
||||
}
|
||||
go progress.ExecuteTask(fmt.Sprintf("Generating transcode for %s", scene.Path), func() {
|
||||
task.Start(&wg)
|
||||
task.Start()
|
||||
wg.Done()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -334,7 +336,8 @@ func (s *singleton) Generate(ctx context.Context, input models.GenerateMetadataI
|
||||
}
|
||||
wg.Add()
|
||||
go progress.ExecuteTask(fmt.Sprintf("Generating phash for %s", scene.Path), func() {
|
||||
task.Start(&wg)
|
||||
task.Start()
|
||||
wg.Done()
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -367,7 +370,8 @@ func (s *singleton) Generate(ctx context.Context, input models.GenerateMetadataI
|
||||
fileNamingAlgorithm: fileNamingAlgo,
|
||||
}
|
||||
go progress.ExecuteTask(fmt.Sprintf("Generating marker preview for marker ID %d", marker.ID), func() {
|
||||
task.Start(&wg)
|
||||
task.Start()
|
||||
wg.Done()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -421,9 +425,7 @@ func (s *singleton) generateScreenshot(ctx context.Context, sceneId string, at *
|
||||
fileNamingAlgorithm: config.GetInstance().GetVideoFileNamingAlgorithm(),
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
task.Start(&wg)
|
||||
task.Start()
|
||||
|
||||
logger.Infof("Generate screenshot finished")
|
||||
})
|
||||
@@ -607,7 +609,11 @@ func (s *singleton) MigrateHash(ctx context.Context) int {
|
||||
wg.Add(1)
|
||||
|
||||
task := MigrateHashTask{Scene: scene, fileNamingAlgorithm: fileNamingAlgo}
|
||||
go task.Start(&wg)
|
||||
go func() {
|
||||
task.Start()
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
@@ -811,7 +817,8 @@ func (s *singleton) StashBoxBatchPerformerTag(ctx context.Context, input models.
|
||||
for _, task := range tasks {
|
||||
wg.Add(1)
|
||||
progress.ExecuteTask(task.Description(), func() {
|
||||
task.Start(&wg)
|
||||
task.Start()
|
||||
wg.Done()
|
||||
})
|
||||
|
||||
progress.Increment()
|
||||
|
||||
Reference in New Issue
Block a user