comparison pkg/imports/sr.go @ 991:a301d240905f

Decoupled import job creation and job execution with a factory function. This is needed for persistence purposes.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 22 Oct 2018 10:45:17 +0200
parents 7dfd3db94e6d
children a244b18cb916
comparison
equal deleted inserted replaced
990:3907a7b98067 991:a301d240905f
22 shp "github.com/jonas-p/go-shp" 22 shp "github.com/jonas-p/go-shp"
23 23
24 "gemma.intevation.de/gemma/pkg/octree" 24 "gemma.intevation.de/gemma/pkg/octree"
25 ) 25 )
26 26
27 type SoundingResult struct { 27 type SoundingResult string
28 Who string
29 Dir string
30 }
31 28
32 const SoundingResultDateFormat = "2006-01-02" 29 const SoundingResultDateFormat = "2006-01-02"
33 30
34 type ( 31 type (
35 SoundingResultDate struct{ time.Time } 32 SoundingResultDate struct{ time.Time }
46 43
47 const ( 44 const (
48 contourStepWidth = 0.5 45 contourStepWidth = 0.5
49 contourTolerance = 0.1 46 contourTolerance = 0.1
50 ) 47 )
48
49 const SRJobKind JobKind = "sr"
50
51 func init() {
52 RegisterJobCreator(SRJobKind, func(_ JobKind, data string) (Job, error) {
53 return SoundingResult(data), nil
54 })
55 }
51 56
52 const ( 57 const (
53 checkDepthReferenceSQL = ` 58 checkDepthReferenceSQL = `
54 SELECT true FROM depth_references WHERE depth_reference = $1` 59 SELECT true FROM depth_references WHERE depth_reference = $1`
55 60
122 FROM waterway.sounding_results sr 127 FROM waterway.sounding_results sr
123 WHERE id = $1 128 WHERE id = $1
124 ` 129 `
125 ) 130 )
126 131
127 func (sr *SoundingResult) Do(conn *sql.Conn, feedback Feedback) error { 132 func (sr SoundingResult) Do(conn *sql.Conn, feedback Feedback) error {
128 133
129 z, err := zip.OpenReader(filepath.Join(sr.Dir, "sr.zip")) 134 z, err := zip.OpenReader(filepath.Join(string(sr), "sr.zip"))
130 if err != nil { 135 if err != nil {
131 return err 136 return err
132 } 137 }
133 defer z.Close() 138 defer z.Close()
134 139
255 *srd = SoundingResultDate{d} 260 *srd = SoundingResultDate{d}
256 } 261 }
257 return err 262 return err
258 } 263 }
259 264
260 func (sr *SoundingResult) User() string { 265 func (sr SoundingResult) CleanUp() error {
261 return sr.Who 266 return os.RemoveAll(string(sr))
262 }
263
264 func (sr *SoundingResult) CleanUp() error {
265 return os.RemoveAll(sr.Dir)
266 } 267 }
267 268
268 func find(needle string, haystack []*zip.File) *zip.File { 269 func find(needle string, haystack []*zip.File) *zip.File {
269 needle = strings.ToLower(needle) 270 needle = strings.ToLower(needle)
270 for _, straw := range haystack { 271 for _, straw := range haystack {