diff --git a/manager/task_export.go b/manager/task_export.go index b4d6f2ee7..cc5ed8409 100644 --- a/manager/task_export.go +++ b/manager/task_export.go @@ -19,6 +19,7 @@ type ExportTask struct { } func (t *ExportTask) Start(wg *sync.WaitGroup) { + defer wg.Done() // @manager.total = Scene.count + Gallery.count + Performer.count + Studio.count t.Mappings = &jsonschema.Mappings{} @@ -36,8 +37,6 @@ func (t *ExportTask) Start(wg *sync.WaitGroup) { } t.ExportScrapedItems(ctx) - - wg.Done() } func (t *ExportTask) ExportScenes(ctx context.Context) { diff --git a/manager/task_generate_markers.go b/manager/task_generate_markers.go index d9f8252c2..2f0b6a09f 100644 --- a/manager/task_generate_markers.go +++ b/manager/task_generate_markers.go @@ -16,18 +16,18 @@ type GenerateMarkersTask struct { } func (t *GenerateMarkersTask) Start(wg *sync.WaitGroup) { + defer wg.Done() + instance.Paths.Generated.EmptyTmpDir() qb := models.NewSceneMarkerQueryBuilder() sceneMarkers, _ := qb.FindBySceneID(t.Scene.ID, nil) if len(sceneMarkers) == 0 { - wg.Done() return } videoFile, err := ffmpeg.NewVideoFile(instance.Paths.FixedPaths.FFProbe, t.Scene.Path) if err != nil { logger.Errorf("error reading video file: %s", err.Error()) - wg.Done() return } @@ -74,6 +74,4 @@ func (t *GenerateMarkersTask) Start(wg *sync.WaitGroup) { } } } - - wg.Done() } diff --git a/manager/task_generate_preview.go b/manager/task_generate_preview.go index 778a6fced..30b81f187 100644 --- a/manager/task_generate_preview.go +++ b/manager/task_generate_preview.go @@ -13,39 +13,35 @@ type GeneratePreviewTask struct { } func (t *GeneratePreviewTask) Start(wg *sync.WaitGroup) { + defer wg.Done() + videoFilename := t.videoFilename() imageFilename := t.imageFilename() - if t.doesPreviewExist(videoFilename, imageFilename) { - wg.Done() + if t.doesPreviewExist(t.Scene.Checksum) { return } videoFile, err := ffmpeg.NewVideoFile(instance.Paths.FixedPaths.FFProbe, t.Scene.Path) if err != nil { logger.Errorf("error reading video file: %s", err.Error()) - wg.Done() return } generator, err := NewPreviewGenerator(*videoFile, videoFilename, imageFilename, instance.Paths.Generated.Screenshots) if err != nil { logger.Errorf("error creating preview generator: %s", err.Error()) - wg.Done() return } if err := generator.Generate(); err != nil { logger.Errorf("error generating preview: %s", err.Error()) - wg.Done() return } - - wg.Done() } -func (t *GeneratePreviewTask) doesPreviewExist(videoFilename string, imageFilename string) bool { - videoExists, _ := utils.FileExists(instance.Paths.Scene.GetStreamPreviewPath(videoFilename)) - imageExists, _ := utils.FileExists(instance.Paths.Scene.GetStreamPreviewImagePath(imageFilename)) +func (t *GeneratePreviewTask) doesPreviewExist(sceneChecksum string) bool { + videoExists, _ := utils.FileExists(instance.Paths.Scene.GetStreamPreviewPath(sceneChecksum)) + imageExists, _ := utils.FileExists(instance.Paths.Scene.GetStreamPreviewImagePath(sceneChecksum)) return videoExists && imageExists } diff --git a/manager/task_generate_sprite.go b/manager/task_generate_sprite.go index c0a8e2557..ea8a70b26 100644 --- a/manager/task_generate_sprite.go +++ b/manager/task_generate_sprite.go @@ -13,15 +13,15 @@ type GenerateSpriteTask struct { } func (t *GenerateSpriteTask) Start(wg *sync.WaitGroup) { + defer wg.Done() + if t.doesSpriteExist(t.Scene.Checksum) { - wg.Done() return } videoFile, err := ffmpeg.NewVideoFile(instance.Paths.FixedPaths.FFProbe, t.Scene.Path) if err != nil { logger.Errorf("error reading video file: %s", err.Error()) - wg.Done() return } @@ -30,17 +30,13 @@ func (t *GenerateSpriteTask) Start(wg *sync.WaitGroup) { generator, err := NewSpriteGenerator(*videoFile, imagePath, vttPath, 9, 9) if err != nil { logger.Errorf("error creating sprite generator: %s", err.Error()) - wg.Done() return } if err := generator.Generate(); err != nil { logger.Errorf("error generating sprite: %s", err.Error()) - wg.Done() return } - - wg.Done() } func (t *GenerateSpriteTask) doesSpriteExist(sceneChecksum string) bool { diff --git a/manager/task_import.go b/manager/task_import.go index 97ff0b81c..7664de0c9 100644 --- a/manager/task_import.go +++ b/manager/task_import.go @@ -20,9 +20,12 @@ type ImportTask struct { } func (t *ImportTask) Start(wg *sync.WaitGroup) { + defer wg.Done() + t.Mappings, _ = instance.JSON.getMappings() if t.Mappings == nil { - panic("missing mappings json") + logger.Error("missing mappings json") + return } scraped, _ := instance.JSON.getScraped() if scraped == nil { @@ -41,8 +44,6 @@ func (t *ImportTask) Start(wg *sync.WaitGroup) { t.ImportScrapedItems(ctx) t.ImportScenes(ctx) - - wg.Done() } func (t *ImportTask) ImportPerformers(ctx context.Context) { @@ -231,6 +232,7 @@ func (t *ImportTask) ImportTags(ctx context.Context) { for i, mappingJSON := range t.Mappings.Scenes { index := i + 1 if mappingJSON.Checksum == "" || mappingJSON.Path == "" { + _ = tx.Rollback() logger.Warn("[tags] scene mapping without checksum or path: ", mappingJSON) return } @@ -350,6 +352,7 @@ func (t *ImportTask) ImportScenes(ctx context.Context) { for i, mappingJSON := range t.Mappings.Scenes { index := i + 1 if mappingJSON.Checksum == "" || mappingJSON.Path == "" { + _ = tx.Rollback() logger.Warn("[scenes] scene mapping without checksum or path: ", mappingJSON) return } diff --git a/utils/file.go b/utils/file.go index 0ffa5f52f..e2b0ad0da 100644 --- a/utils/file.go +++ b/utils/file.go @@ -37,7 +37,6 @@ func EnsureDir(path string) error { return err } -// TODO test func RemoveDir(path string) error { return os.RemoveAll(path) }