diff options
Diffstat (limited to 'src/helsinki.at/rhimportd')
-rw-r--r-- | src/helsinki.at/rhimportd/main.go | 92 |
1 files changed, 68 insertions, 24 deletions
diff --git a/src/helsinki.at/rhimportd/main.go b/src/helsinki.at/rhimportd/main.go index 32b81d7..8f1c65d 100644 --- a/src/helsinki.at/rhimportd/main.go +++ b/src/helsinki.at/rhimportd/main.go @@ -28,8 +28,8 @@ import ( "flag" "log" "os" - "os/signal" - "sync" + // "os/signal" + // "sync" "helsinki.at/rhimport" // "io/ioutil" @@ -42,7 +42,7 @@ var ( ) func main() { - web_addr_s := flag.String("web-addr", ":4000", "addr:port to listen on") + // web_addr_s := flag.String("web-addr", ":4000", "addr:port to listen on") rdconf_s := flag.String("rdconf", "/etc/rd.conf", "path to the Rivendell config file") rdxport_url_s := flag.String("rdxport-url", "http://localhost/rd-bin/rdxport.cgi", "the url to the Rivendell web-api") temp_dir_s := flag.String("tmp-dir", os.TempDir(), "path to temporary files") @@ -68,30 +68,74 @@ func main() { } defer rddb.Cleanup() - var wg sync.WaitGroup + sessions, err := rhimport.NewSessionStore(conf) + if err != nil { + rhl.Println("Error initializing Session Store:", err) + return + } + defer sessions.Cleanup() - wg.Add(1) - go func() { - defer wg.Done() - rhl.Println("start web-ctrl") - StartControlWeb(*web_addr_s, conf, rddb) - rhl.Println("web-ctrl finished") - }() + ctx := rhimport.ImportContext{UserName: "hugo"} + var id string + if id, err = sessions.NewSession(ctx); err != nil { + rhl.Println("NewSession:", err) + } - alldone := make(chan bool) - go func() { - defer func() { alldone <- true }() - wg.Wait() - }() + pchan := make(chan rhimport.ProgressData) + if err = sessions.AddProgressHandler(ctx.UserName, id, "mydata", pchan); err != nil { + rhl.Println("AddProgressHanlder:", err) + } - c := make(chan os.Signal, 1) - signal.Notify(c, os.Interrupt) + dchan := make(chan rhimport.ImportResult) + if err = sessions.AddDoneHandler(ctx.UserName, id, "mydata", dchan); err != nil { + rhl.Println("AddDoneHanlder:", err) + } - select { - case <-c: - rhl.Println("received interrupt, shutdown") - return - case <-alldone: - return + if err = sessions.Run(ctx.UserName, id); err != nil { + rhl.Println("Run:", err) } + + var id2 string + if id2, err = sessions.NewSession(ctx); err != nil { + rhl.Println("NewSession:", err) + } + + if err = sessions.Remove(ctx.UserName, id); err != nil { + rhl.Println("Remove:", err) + } + + if err = sessions.Remove(ctx.UserName, id); err != nil { + rhl.Println("Remove:", err) + } + + if err = sessions.Remove(ctx.UserName, id2); err != nil { + rhl.Println("Remove:", err) + } + + // var wg sync.WaitGroup + + // wg.Add(1) + // go func() { + // defer wg.Done() + // rhl.Println("start web-ctrl") + // StartControlWeb(*web_addr_s, conf, rddb) + // rhl.Println("web-ctrl finished") + // }() + + // alldone := make(chan bool) + // go func() { + // defer func() { alldone <- true }() + // wg.Wait() + // }() + + // c := make(chan os.Signal, 1) + // signal.Notify(c, os.Interrupt) + + // select { + // case <-c: + // rhl.Println("received interrupt, shutdown") + // return + // case <-alldone: + // return + // } } |