diff options
Diffstat (limited to 'src/helsinki.at/rhimportd')
-rw-r--r-- | src/helsinki.at/rhimportd/ctrlTelnet.go | 3 | ||||
-rw-r--r-- | src/helsinki.at/rhimportd/main.go | 57 |
2 files changed, 56 insertions, 4 deletions
diff --git a/src/helsinki.at/rhimportd/ctrlTelnet.go b/src/helsinki.at/rhimportd/ctrlTelnet.go index 687652c..74e396f 100644 --- a/src/helsinki.at/rhimportd/ctrlTelnet.go +++ b/src/helsinki.at/rhimportd/ctrlTelnet.go @@ -264,9 +264,10 @@ func (c *TelnetClient) handle_cmd_show(args []string) { } } -func telnet_progress_callback(step int, step_name string, progress float64, userdata interface{}) { +func telnet_progress_callback(step int, step_name string, progress float64, userdata interface{}) bool { out := userdata.(chan<- string) out <- fmt.Sprintf("%s: %3.2f%%\r", step_name, progress*100) + return true } func telnet_cmd_run(ctx rhimport.ImportContext, out chan<- string) { diff --git a/src/helsinki.at/rhimportd/main.go b/src/helsinki.at/rhimportd/main.go index b90df0a..aeb7194 100644 --- a/src/helsinki.at/rhimportd/main.go +++ b/src/helsinki.at/rhimportd/main.go @@ -26,6 +26,7 @@ package main import ( "flag" + "fmt" "log" "os" "os/signal" @@ -42,6 +43,33 @@ var ( //rhdl = log.New(ioutil.Discard, "[rhimportd-dbg]\t", log.LstdFlags) ) +func session_test_progress1(step int, step_name string, progress float64, userdata interface{}) bool { + out := userdata.(chan<- string) + select { + case out <- fmt.Sprintf("CB1 %d, %s: %3.2f%%", step, step_name, progress*100): + default: + } + if step > 1 { + return false + } + return true +} + +func session_test_progress2(step int, step_name string, progress float64, userdata interface{}) bool { + out := userdata.(chan<- string) + select { + case out <- fmt.Sprintf("CB2 %d, %s: %3.2f%%", step, step_name, progress*100): + default: + } + return true +} + +func session_test_done(res rhimport.ImportResult, userdata interface{}) bool { + done := userdata.(chan<- rhimport.ImportResult) + done <- res + return true +} + func session_test(conf *rhimport.Config, rddb *rhimport.RdDbChan) { sessions, err := rhimport.NewSessionStore(conf) if err != nil { @@ -55,7 +83,8 @@ func session_test(conf *rhimport.Config, rddb *rhimport.RdDbChan) { ctx := rhimport.NewImportContext(conf, rddb, "heslinki") ctx.Trusted = true ctx.ShowId = 10002 - ctx.SourceUri = "fake://10" + ctx.ClearShowCarts = true + ctx.SourceUri = "http://www.tonycuffe.com/mp3/tail%20toddle.mp3" id, session, err := store.New(ctx) if err != nil { @@ -63,11 +92,33 @@ func session_test(conf *rhimport.Config, rddb *rhimport.RdDbChan) { return } + pch := make(chan string, 1000) + if err = session.AddProgressHandler((chan<- string)(pch), session_test_progress1); err != nil { + rhl.Printf("MAIN: Error Session.AddProgressHandler(): %s", err) + } + dch := make(chan rhimport.ImportResult) + if err = session.AddDoneHandler((chan<- rhimport.ImportResult)(dch), session_test_done); err != nil { + rhl.Printf("MAIN: Error Session.AddDoneHandler(): %s", err) + } + rhl.Printf("MAIN: calling run for heslinki/%s", id) session.Run() - rhl.Printf("MAIN: waiting for 2 secondes") - time.Sleep(5 * time.Second) + time.Sleep(500 * time.Millisecond) + + if err = session.AddProgressHandler((chan<- string)(pch), session_test_progress2); err != nil { + rhl.Printf("MAIN: Error Session.AddProgressHandler(): %s", err) + } + + for { + select { + case p := <-pch: + fmt.Println(p) + case r := <-dch: + fmt.Printf("Import finished: %+v\n", r) + break + } + } rhl.Printf("MAIN: calling remove for heslinki/%s", id) if err = store.Remove("heslinki", id); err != nil { |