summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-12-21 07:45:13 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-12-21 07:45:13 (GMT)
commita71ce473ac19e8ba5cf69f0d1375807529d92b11 (patch)
treef3e79711efc559b4950bec18bc548634661908fb /src
parent75dd88f110c117b7fc73b83b13efd2385347f1b9 (diff)
minor cleanup for session testing
Diffstat (limited to 'src')
-rw-r--r--src/helsinki.at/rhimport/session.go7
-rw-r--r--src/helsinki.at/rhimportd/main.go97
2 files changed, 53 insertions, 51 deletions
diff --git a/src/helsinki.at/rhimport/session.go b/src/helsinki.at/rhimport/session.go
index ce84053..8f20958 100644
--- a/src/helsinki.at/rhimport/session.go
+++ b/src/helsinki.at/rhimport/session.go
@@ -149,7 +149,9 @@ func (self *Session) dispatchRequests() {
for {
select {
case <-self.runChan:
- self.run()
+ if !self.running {
+ self.run()
+ }
case <-self.cancelChan:
if self.running {
rhdl.Println("Session: canceling running imports is not yet implemented")
@@ -168,8 +170,6 @@ func (self *Session) dispatchRequests() {
self.running = false
rhdl.Printf("Session: import is done: %+v", result)
// TODO: call all subscribed done handler
- // TODO: send remove request to session store?
- return
}
}
}
@@ -185,6 +185,7 @@ func (self *Session) getInterface() *SessionChan {
func (self *Session) Cleanup() {
// TODO: this blocks if dispatchRequests has ended already...
+ // or if cancel doesn't work...
self.cancelChan <- true
<-self.done
close(self.done)
diff --git a/src/helsinki.at/rhimportd/main.go b/src/helsinki.at/rhimportd/main.go
index 51a406e..4b6ddf4 100644
--- a/src/helsinki.at/rhimportd/main.go
+++ b/src/helsinki.at/rhimportd/main.go
@@ -43,34 +43,7 @@ var (
//rhdl = log.New(ioutil.Discard, "[rhimportd-dbg]\t", log.LstdFlags)
)
-func main() {
- // web_addr_s := flag.String("web-addr", ":4080", "addr:port to listen on")
- // telnet_addr_s := flag.String("telnet-addr", ":4023", "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")
- local_fetch_dir_s := flag.String("local-fetch-dir", os.TempDir(), "path to files that can be imported using local://")
- help := flag.Bool("help", false, "show usage")
-
- flag.Parse()
- if *help {
- flag.Usage()
- return
- }
-
- conf, err := rhimport.NewConfig(rdconf_s, rdxport_url_s, temp_dir_s, local_fetch_dir_s)
- if err != nil {
- rhl.Println("Error reading configuration:", err)
- return
- }
-
- rddb, err := rhimport.NewRdDb(conf)
- if err != nil {
- rhl.Println("Error initializing Rivdenll DB:", err)
- return
- }
- defer rddb.Cleanup()
-
+func session_test(conf *rhimport.Config, rddb *rhimport.RdDbChan) {
sessions, err := rhimport.NewSessionStore(conf)
if err != nil {
rhl.Println("Error initializing Session Store:", err)
@@ -80,7 +53,7 @@ func main() {
store := sessions.GetInterface()
- ctx := rhimport.NewImportContext(conf, rddb.GetInterface(), "hugo")
+ ctx := rhimport.NewImportContext(conf, rddb, "hugo")
id, session, err := store.New(ctx)
if err != nil {
rhl.Printf("Error SessionStore.New(): %s", err)
@@ -93,39 +66,67 @@ func main() {
fmt.Printf("\n\nSESSION_STORE: %+v\n\n", sessions)
- time.Sleep(12 * time.Second)
+ time.Sleep(5 * time.Second)
+
+ store.Remove("hugo", id)
+ fmt.Printf("\n\nSESSION_STORE: %+v\n\n", sessions)
+
+ time.Sleep(6 * time.Second)
fmt.Printf("\n\nSESSION_STORE: %+v\n\n", sessions)
store.Remove("hugo", id)
fmt.Printf("\n\nSESSION_STORE: %+v\n\n", sessions)
+}
+
+func main() {
+ web_addr_s := flag.String("web-addr", ":4080", "addr:port to listen on")
+ telnet_addr_s := flag.String("telnet-addr", ":4023", "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")
+ local_fetch_dir_s := flag.String("local-fetch-dir", os.TempDir(), "path to files that can be imported using local://")
+ help := flag.Bool("help", false, "show usage")
+
+ flag.Parse()
+ if *help {
+ flag.Usage()
+ return
+ }
+
+ conf, err := rhimport.NewConfig(rdconf_s, rdxport_url_s, temp_dir_s, local_fetch_dir_s)
+ if err != nil {
+ rhl.Println("Error reading configuration:", err)
+ return
+ }
+
+ rddb, err := rhimport.NewRdDb(conf)
+ if err != nil {
+ rhl.Println("Error initializing Rivdenll DB:", err)
+ return
+ }
+ defer rddb.Cleanup()
+
+ // go session_test(conf, rddb.GetInterface())
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
- for {
- time.Sleep(10 * time.Second)
- }
+ rhl.Println("starting web-ctrl")
+ StartControlWeb(*web_addr_s, conf, rddb.GetInterface())
+ rhl.Println("web-ctrl finished")
}()
- // wg.Add(1)
- // go func() {
- // defer wg.Done()
- // rhl.Println("starting web-ctrl")
- // StartControlWeb(*web_addr_s, conf, rddb.GetInterface())
- // rhl.Println("web-ctrl finished")
- // }()
-
- // wg.Add(1)
- // go func() {
- // defer wg.Done()
- // rhl.Println("starting telnet-ctrl")
- // StartControlTelnet(*telnet_addr_s, conf, rddb.GetInterface())
- // rhl.Println("telnet-ctrl finished")
- // }()
+ wg.Add(1)
+ go func() {
+ defer wg.Done()
+ rhl.Println("starting telnet-ctrl")
+ StartControlTelnet(*telnet_addr_s, conf, rddb.GetInterface())
+ rhl.Println("telnet-ctrl finished")
+ }()
alldone := make(chan bool)
go func() {