diff options
author | Christian Pointner <equinox@helsinki.at> | 2016-01-08 00:51:37 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2016-01-08 00:51:37 (GMT) |
commit | 63db9233d681006b1b1fb4999825d21e79dfcec5 (patch) | |
tree | 0683ed60874493597cfd6e0b87fd2cb33c6f6ea1 /src/rhimportd/ctrlWatchDir.go | |
parent | 92f96b74e3816214a65973b3b362424d110b3a77 (diff) |
move rddb to rhrd-go
Diffstat (limited to 'src/rhimportd/ctrlWatchDir.go')
-rw-r--r-- | src/rhimportd/ctrlWatchDir.go | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/rhimportd/ctrlWatchDir.go b/src/rhimportd/ctrlWatchDir.go index 6f84c15..037f8ea 100644 --- a/src/rhimportd/ctrlWatchDir.go +++ b/src/rhimportd/ctrlWatchDir.go @@ -28,6 +28,7 @@ import ( "encoding/json" "fmt" "helsinki.at/rhimport" + "helsinki.at/rhrd-go/rddb" "net/http" "os" "path/filepath" @@ -97,7 +98,7 @@ func watchDirResponse(filename string, result *rhimport.Result) { watchDirWriteResponse(filename, &watchDirResponseData{result.ResponseCode, result.ErrorString, result.Cart, result.Cut}) } -func watchDirParseRequest(conf *rhimport.Config, rddb *rhimport.RdDbChan, req *os.File) (ctx *rhimport.Context, err error) { +func watchDirParseRequest(conf *rhimport.Config, db *rddb.DBChan, req *os.File) (ctx *rhimport.Context, err error) { decoder := json.NewDecoder(req) reqdata := newWatchDirRequestData(conf) @@ -106,7 +107,7 @@ func watchDirParseRequest(conf *rhimport.Config, rddb *rhimport.RdDbChan, req *o return } - ctx = rhimport.NewContext(conf, rddb) + ctx = rhimport.NewContext(conf, db) ctx.UserName = reqdata.UserName ctx.Trusted = true ctx.ShowId = reqdata.ShowId @@ -123,7 +124,7 @@ func watchDirParseRequest(conf *rhimport.Config, rddb *rhimport.RdDbChan, req *o return } -func watchDirHandler(conf *rhimport.Config, rddb *rhimport.RdDbChan, ctx *rhimport.Context, filename string) { +func watchDirHandler(conf *rhimport.Config, db *rddb.DBChan, ctx *rhimport.Context, filename string) { rhdl.Printf("WatchDirHandler: request for '%s'", filename) var err error @@ -156,7 +157,7 @@ func watchDirHandler(conf *rhimport.Config, rddb *rhimport.RdDbChan, ctx *rhimpo return } -func watchDirRun(dir *os.File, conf *rhimport.Config, rddb *rhimport.RdDbChan) { +func watchDirRun(dir *os.File, conf *rhimport.Config, db *rddb.DBChan) { rhl.Printf("watch-dir-ctrl: watching for files in %s", dir.Name()) for { var err error @@ -181,11 +182,11 @@ func watchDirRun(dir *os.File, conf *rhimport.Config, rddb *rhimport.RdDbChan) { rhl.Printf("watch-dir-ctrl: error reading new file: %s", err) continue } - if ctx, err := watchDirParseRequest(conf, rddb, file); err == nil { + if ctx, err := watchDirParseRequest(conf, db, file); err == nil { file.Close() dstname := strings.TrimSuffix(srcname, ".new") + ".running" os.Rename(srcname, dstname) - go watchDirHandler(conf, rddb, ctx, dstname) + go watchDirHandler(conf, db, ctx, dstname) } else { // ignoring files with json errors -> maybe the file has not been written completely file.Close() rhdl.Printf("watch-dir-ctrl: new file %s parser error: %s, ignoring for now", srcname, err) @@ -197,7 +198,7 @@ func watchDirRun(dir *os.File, conf *rhimport.Config, rddb *rhimport.RdDbChan) { } } -func StartWatchDir(dirname string, conf *rhimport.Config, rddb *rhimport.RdDbChan) { +func StartWatchDir(dirname string, conf *rhimport.Config, db *rddb.DBChan) { for { time.Sleep(5 * time.Second) dir, err := os.Open(dirname) @@ -214,6 +215,6 @@ func StartWatchDir(dirname string, conf *rhimport.Config, rddb *rhimport.RdDbCha continue } } - watchDirRun(dir, conf, rddb) + watchDirRun(dir, conf, db) } } |