From 4a358bab91c53ac951567c0f25d08368095b843a Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 21 Dec 2015 22:41:22 +0100 Subject: improved error handling and reporting, canceling running requests when telnet client leaves diff --git a/fetcher.go b/fetcher.go index 24635d1..1f0b364 100644 --- a/fetcher.go +++ b/fetcher.go @@ -116,6 +116,7 @@ func FetchFileCurl(ctx *ImportContext, res *FetchResult, uri *url.URL) (err erro easy.Setopt(curl.OPT_NOPROGRESS, false) easy.Setopt(curl.OPT_PROGRESSFUNCTION, func(dltotal, dlnow, ultotal, ulnow float64, userdata interface{}) bool { if ctx.Cancel != nil && len(ctx.Cancel) > 0 { + rhl.Printf("downloading '%s' got canceled", ctx.SourceUri) res.ResponseCode = http.StatusNoContent res.ErrorString = "canceled" return false @@ -129,6 +130,11 @@ func FetchFileCurl(ctx *ImportContext, res *FetchResult, uri *url.URL) (err erro easy.Setopt(curl.OPT_PROGRESSDATA, ctx) if err = easy.Perform(); err != nil { + if cbdata.File != nil { + rhdl.Printf("Removing stale file: %s", cbdata.filename) + os.Remove(cbdata.filename) + os.Remove(path.Dir(cbdata.filename)) + } if res.ResponseCode == http.StatusNoContent { err = nil } else { @@ -176,6 +182,7 @@ func FetchFileFake(ctx *ImportContext, res *FetchResult, uri *url.URL) error { } else { for i := uint(0); i < uint(duration); i++ { if ctx.Cancel != nil && len(ctx.Cancel) > 0 { + rhl.Printf("faking got canceled") res.ResponseCode = http.StatusNoContent res.ErrorString = "canceled" return nil diff --git a/importer.go b/importer.go index 512daf6..1bfdf0c 100644 --- a/importer.go +++ b/importer.go @@ -516,6 +516,7 @@ func import_audio(ctx *ImportContext, res *ImportResult) (err error) { if err = easy.Perform(); err != nil { if res.ResponseCode == http.StatusNoContent { + rhl.Printf("import to cart/cat %d/%d got canceled", ctx.Cart, ctx.Cut) res.Cart = ctx.Cart res.Cut = ctx.Cut err = nil @@ -626,7 +627,7 @@ func cleanup_files(ctx *ImportContext) { func ImportFile(ctx *ImportContext) (res *ImportResult, err error) { defer cleanup_files(ctx) - rhdl.Printf("importer: ImportFile called with: show-id: %d, pool-name: '%s', cart/cut: %d/%d", ctx.ShowId, ctx.GroupName, ctx.Cart, ctx.Cut) + rhl.Printf("importer: ImportFile called with: show-id: %d, pool-name: '%s', cart/cut: %d/%d", ctx.ShowId, ctx.GroupName, ctx.Cart, ctx.Cut) if ctx.ProgressCallBack != nil { ctx.ProgressCallBack(2, "importing", 0.0, ctx.ProgressCallBackData) @@ -696,6 +697,7 @@ func ImportFile(ctx *ImportContext) (res *ImportResult, err error) { return } if res.ResponseCode != http.StatusOK { + rhl.Printf("Fileimport has failed (Cart/Cut %d/%d): %s", res.Cart, res.Cut, res.ErrorString) rmres := ImportResult{ResponseCode: http.StatusOK} if rmCartOnErr { if err = remove_cart(ctx, &rmres); err != nil { @@ -706,10 +708,12 @@ func ImportFile(ctx *ImportContext) (res *ImportResult, err error) { return } } + } else { + rhl.Printf("File got succesfully imported into Cart/Cut %d/%d", res.Cart, res.Cut) } } else { res.ResponseCode = http.StatusBadRequest - res.ErrorString = "The request doesn't contain enough information to be processed" + res.ErrorString = "importer: The request doesn't contain enough information to be processed" } return -- cgit v0.10.2