Mercurial > gemma
comparison pkg/imports/sr.go @ 1531:24445a618513
Added stub for bottleneck importer.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 07 Dec 2018 13:08:17 +0100 |
parents | 5874cedd7f91 |
children | 056a86b24be2 |
comparison
equal
deleted
inserted
replaced
1530:e7830ab6bacc | 1531:24445a618513 |
---|---|
19 "bufio" | 19 "bufio" |
20 "context" | 20 "context" |
21 "crypto/sha1" | 21 "crypto/sha1" |
22 "database/sql" | 22 "database/sql" |
23 "encoding/hex" | 23 "encoding/hex" |
24 "encoding/json" | |
25 "errors" | 24 "errors" |
26 "fmt" | 25 "fmt" |
27 "io" | 26 "io" |
28 "math" | 27 "math" |
29 "os" | 28 "os" |
74 RegisterJobCreator(SRJobKind, srJobCreator{}) | 73 RegisterJobCreator(SRJobKind, srJobCreator{}) |
75 } | 74 } |
76 | 75 |
77 func (srJobCreator) Create(_ JobKind, data string) (Job, error) { | 76 func (srJobCreator) Create(_ JobKind, data string) (Job, error) { |
78 sr := new(SoundingResult) | 77 sr := new(SoundingResult) |
79 if err := sr.FromString(data); err != nil { | 78 if err := common.FromJSONString(data, sr); err != nil { |
80 return nil, err | 79 return nil, err |
81 } | 80 } |
82 return sr, nil | 81 return sr, nil |
83 } | 82 } |
84 | 83 |
167 FROM waterway.sounding_results sr | 166 FROM waterway.sounding_results sr |
168 WHERE id = $1 | 167 WHERE id = $1 |
169 ` | 168 ` |
170 ) | 169 ) |
171 | 170 |
172 // FromString revives a SoundingResult import from a string. | |
173 func (sr *SoundingResult) FromString(data string) error { | |
174 return json.NewDecoder(strings.NewReader(data)).Decode(sr) | |
175 } | |
176 | |
177 // ToString serializes a SoundingResult import into a string to | |
178 // be revived by FromString. | |
179 func (sr *SoundingResult) ToString() (string, error) { | |
180 var b strings.Builder | |
181 if err := json.NewEncoder(&b).Encode(sr); err != nil { | |
182 return "", err | |
183 } | |
184 return b.String(), nil | |
185 } | |
186 | |
187 // Do executes the actual sounding result import. | 171 // Do executes the actual sounding result import. |
188 func (sr *SoundingResult) Do( | 172 func (sr *SoundingResult) Do( |
189 ctx context.Context, | 173 ctx context.Context, |
190 importID int64, | 174 importID int64, |
191 conn *sql.Conn, | 175 conn *sql.Conn, |