diff options
Diffstat (limited to 'src/rhimportd/ctrlWatchDir.go')
-rw-r--r-- | src/rhimportd/ctrlWatchDir.go | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/rhimportd/ctrlWatchDir.go b/src/rhimportd/ctrlWatchDir.go index 7290597..7ab0a12 100644 --- a/src/rhimportd/ctrlWatchDir.go +++ b/src/rhimportd/ctrlWatchDir.go @@ -49,6 +49,7 @@ type watchDirRequestData struct { AutotrimLevel int `json:"AUTOTRIM_LEVEL"` UseMetaData bool `json:"USE_METADATA"` SourceUri string `json:"SOURCE_URI"` + SourceFilePolicy string `json:"SOURCE_FILE_POLICY"` } func newWatchDirRequestData(conf *rhimport.Config) *watchDirRequestData { @@ -65,6 +66,7 @@ func newWatchDirRequestData(conf *rhimport.Config) *watchDirRequestData { rd.AutotrimLevel = conf.ImportParamDefaults.AutotrimLevel rd.UseMetaData = conf.ImportParamDefaults.UseMetaData rd.SourceUri = "" + rd.SourceFilePolicy = "" return rd } @@ -74,6 +76,7 @@ type watchDirResponseData struct { ErrorString string `json:"ERROR_STRING"` Cart uint `json:"CART_NUMBER"` Cut uint `json:"CUT_NUMBER"` + SourceFile string `json:"SOURCE_FILE"` } func watchDirWriteResponse(filename string, resp *watchDirResponseData) { @@ -90,12 +93,12 @@ func watchDirWriteResponse(filename string, resp *watchDirResponseData) { os.Rename(filename, dstname) } -func watchDirErrorResponse(filename string, code int, errStr string) { - watchDirWriteResponse(filename, &watchDirResponseData{code, errStr, 0, 0}) +func watchDirErrorResponse(filename string, code int, errStr, sourceFile string) { + watchDirWriteResponse(filename, &watchDirResponseData{code, errStr, 0, 0, sourceFile}) } func watchDirResponse(filename string, result *rhimport.Result) { - watchDirWriteResponse(filename, &watchDirResponseData{result.ResponseCode, result.ErrorString, result.Cart, result.Cut}) + watchDirWriteResponse(filename, &watchDirResponseData{result.ResponseCode, result.ErrorString, result.Cart, result.Cut, result.SourceFile}) } func watchDirParseRequest(conf *rhimport.Config, db *rddb.DBChan, req *os.File) (ctx *rhimport.Context, err error) { @@ -121,6 +124,7 @@ func watchDirParseRequest(conf *rhimport.Config, db *rddb.DBChan, req *os.File) ctx.AutotrimLevel = reqdata.AutotrimLevel ctx.UseMetaData = reqdata.UseMetaData ctx.SourceUri = reqdata.SourceUri + err = ctx.SourceFilePolicy.FromString(reqdata.SourceFilePolicy) return } @@ -129,22 +133,22 @@ func watchDirHandler(conf *rhimport.Config, db *rddb.DBChan, ctx *rhimport.Conte var err error if err = ctx.SanityCheck(); err != nil { - watchDirErrorResponse(filename, http.StatusBadRequest, err.Error()) + watchDirErrorResponse(filename, http.StatusBadRequest, err.Error(), "") return } var res *rhimport.Result if res, err = rhimport.FetchFile(ctx); err != nil { - watchDirErrorResponse(filename, http.StatusInternalServerError, err.Error()) + watchDirErrorResponse(filename, http.StatusInternalServerError, err.Error(), "") return } if res.ResponseCode != http.StatusOK { - watchDirErrorResponse(filename, res.ResponseCode, res.ErrorString) + watchDirErrorResponse(filename, res.ResponseCode, res.ErrorString, "") return } if res, err = rhimport.ImportFile(ctx); err != nil { - watchDirErrorResponse(filename, http.StatusInternalServerError, err.Error()) + watchDirErrorResponse(filename, http.StatusInternalServerError, err.Error(), res.SourceFile) return } if res.ResponseCode == http.StatusOK { @@ -199,8 +203,13 @@ func watchDirRun(dir *os.File, conf *rhimport.Config, db *rddb.DBChan) { } func StartWatchDir(dirname string, conf *rhimport.Config, db *rddb.DBChan) { + first := true for { - time.Sleep(5 * time.Second) + if !first { + time.Sleep(5 * time.Second) + } + first = false + dir, err := os.Open(dirname) if err != nil { rhl.Printf("watch-dir-ctrl: %s", err) @@ -218,6 +227,7 @@ func StartWatchDir(dirname string, conf *rhimport.Config, db *rddb.DBChan) { } } watchDirRun(dir, conf, db) + rhdl.Printf("watchDirRun: returned - restring in 5 sec...") dir.Close() } } |