summaryrefslogtreecommitdiff
path: root/bookpipeline/cmd/bookpipeline/main.go
diff options
context:
space:
mode:
authorNick White <git@njw.name>2019-09-04 17:01:11 +0100
committerNick White <git@njw.name>2019-09-04 17:01:11 +0100
commit026ebd62c0deec8da03ee22959f433db82bfda4e (patch)
tree7c04cc3dff1dfb3e0e13a6ca930ea1c58c83beed /bookpipeline/cmd/bookpipeline/main.go
parent843ddbb9854ff222ffcf9b9269e5a089499b41e3 (diff)
Ensure any channels that need to be consumed before goroutine is finished are done in the case of an error
Diffstat (limited to 'bookpipeline/cmd/bookpipeline/main.go')
-rw-r--r--bookpipeline/cmd/bookpipeline/main.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/bookpipeline/cmd/bookpipeline/main.go b/bookpipeline/cmd/bookpipeline/main.go
index 44b6ca6..c7dde5b 100644
--- a/bookpipeline/cmd/bookpipeline/main.go
+++ b/bookpipeline/cmd/bookpipeline/main.go
@@ -73,6 +73,7 @@ func download(dl chan string, process chan string, conn Pipeliner, dir string, e
logger.Println("Downloading", key)
err := conn.Download(conn.WIPStorageId(), key, fn)
if err != nil {
+ for range dl {} // consume the rest of the receiving channel so it isn't blocked
close(process)
errc <- err
return
@@ -89,6 +90,7 @@ func up(c chan string, done chan bool, conn Pipeliner, bookname string, errc cha
logger.Println("Uploading", key)
err := conn.Upload(conn.WIPStorageId(), key, path)
if err != nil {
+ for range c {} // consume the rest of the receiving channel so it isn't blocked
errc <- err
return
}
@@ -102,6 +104,7 @@ func preprocess(pre chan string, up chan string, errc chan error, logger *log.Lo
logger.Println("Preprocessing", path)
done, err := preproc.PreProcMulti(path, []float64{0.1, 0.2, 0.4, 0.5}, "binary", 0, true, 5, 30)
if err != nil {
+ for range pre {} // consume the rest of the receiving channel so it isn't blocked
close(up)
errc <- err
return
@@ -121,6 +124,7 @@ func ocr(training string) func(chan string, chan string, chan error, *log.Logger
cmd := exec.Command("tesseract", "-l", training, path, name, "hocr")
err := cmd.Run()
if err != nil {
+ for range toocr {} // consume the rest of the receiving channel so it isn't blocked
close(up)
errc <- errors.New(fmt.Sprintf("Error ocring %s: %s", path, err))
return
@@ -143,6 +147,7 @@ func analyse(toanalyse chan string, up chan string, errc chan error, logger *log
logger.Println("Calculating confidence for", path)
avg, err := hocr.GetAvgConf(path)
if err != nil {
+ for range toanalyse {} // consume the rest of the receiving channel so it isn't blocked
close(up)
errc <- errors.New(fmt.Sprintf("Error retreiving confidence for %s: %s", path, err))
return