comparison pkg/imports/queue.go @ 979:7934b5c1a910

Finally enqueue sounding result import job to import jobs. Sends back the id of the job.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 19 Oct 2018 12:14:53 +0200
parents 544a5cfe07cd
children 3841509f6e9e
comparison
equal deleted inserted replaced
978:544a5cfe07cd 979:7934b5c1a910
10 10
11 "gemma.intevation.de/gemma/pkg/auth" 11 "gemma.intevation.de/gemma/pkg/auth"
12 ) 12 )
13 13
14 type Job interface { 14 type Job interface {
15 Who() string 15 User() string
16 Do(conn *sql.Conn) error 16 Do(conn *sql.Conn) error
17 CleanUp() error 17 CleanUp() error
18 } 18 }
19 19
20 var ( 20 var (
45 queueCond.Wait() 45 queueCond.Wait()
46 } 46 }
47 job = queue.Remove(queue.Front()).(Job) 47 job = queue.Remove(queue.Front()).(Job)
48 queueCond.L.Unlock() 48 queueCond.L.Unlock()
49 49
50 if err := auth.RunAs(job.Who(), context.Background(), job.Do); err != nil { 50 if err := auth.RunAs(job.User(), context.Background(), job.Do); err != nil {
51 log.Printf("import error: %v\n", err) 51 log.Printf("import error: %v\n", err)
52 } 52 }
53 if err := job.CleanUp(); err != nil { 53 if err := job.CleanUp(); err != nil {
54 log.Printf("cleanup error: %v\n", err) 54 log.Printf("cleanup error: %v\n", err)
55 } 55 }