Skip to content

Commit

Permalink
fix(convert): stop conversion on error
Browse files Browse the repository at this point in the history
  • Loading branch information
wailorman committed Nov 13, 2020
1 parent 5165b00 commit fe5310d
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions pkg/media/convert/batch_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strconv"
"sync"

"github.com/wailorman/fftb/pkg/media/info"
mediaInfo "github.com/wailorman/fftb/pkg/media/info"
)

Expand All @@ -16,8 +17,9 @@ type BatchConverter struct {
ConversionStopping chan ConverterTask
ConversionStopped chan ConverterTask

infoGetter mediaInfo.Getter
stopConversion chan struct{}
infoGetter info.Getter
stopConversion chan struct{}
conversionWasStopped bool
}

// NewBatchConverter _
Expand All @@ -31,6 +33,7 @@ func NewBatchConverter(infoGetter mediaInfo.Getter) *BatchConverter {
// Stop _
func (bc *BatchConverter) Stop() {
bc.stopConversion = make(chan struct{})
bc.conversionWasStopped = true
// broadcast to all channel receivers
close(bc.stopConversion)
}
Expand Down Expand Up @@ -78,16 +81,18 @@ func (bc *BatchConverter) Convert(batchTask BatchConverterTask) (
for i := 0; i < batchTask.Parallelism; i++ {
go func() {
for task := range taskQueue {
err := bc.convertOne(task, progress)

if err != nil {
failed <- BatchErrorMessage{
Task: task,
Err: err,
}

if batchTask.StopConversionOnError {
bc.Stop()
if !bc.conversionWasStopped {
err := bc.convertOne(task, progress)

if err != nil {
failed <- BatchErrorMessage{
Task: task,
Err: err,
}

if batchTask.StopConversionOnError {
bc.Stop()
}
}
}

Expand Down

0 comments on commit fe5310d

Please sign in to comment.