diff 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
line wrap: on
line diff
--- a/pkg/imports/sr.go	Mon Oct 22 10:21:22 2018 +0200
+++ b/pkg/imports/sr.go	Mon Oct 22 10:45:17 2018 +0200
@@ -24,10 +24,7 @@
 	"gemma.intevation.de/gemma/pkg/octree"
 )
 
-type SoundingResult struct {
-	Who string
-	Dir string
-}
+type SoundingResult string
 
 const SoundingResultDateFormat = "2006-01-02"
 
@@ -49,6 +46,14 @@
 	contourTolerance = 0.1
 )
 
+const SRJobKind JobKind = "sr"
+
+func init() {
+	RegisterJobCreator(SRJobKind, func(_ JobKind, data string) (Job, error) {
+		return SoundingResult(data), nil
+	})
+}
+
 const (
 	checkDepthReferenceSQL = `
 SELECT true FROM depth_references WHERE depth_reference = $1`
@@ -124,9 +129,9 @@
 `
 )
 
-func (sr *SoundingResult) Do(conn *sql.Conn, feedback Feedback) error {
+func (sr SoundingResult) Do(conn *sql.Conn, feedback Feedback) error {
 
-	z, err := zip.OpenReader(filepath.Join(sr.Dir, "sr.zip"))
+	z, err := zip.OpenReader(filepath.Join(string(sr), "sr.zip"))
 	if err != nil {
 		return err
 	}
@@ -257,12 +262,8 @@
 	return err
 }
 
-func (sr *SoundingResult) User() string {
-	return sr.Who
-}
-
-func (sr *SoundingResult) CleanUp() error {
-	return os.RemoveAll(sr.Dir)
+func (sr SoundingResult) CleanUp() error {
+	return os.RemoveAll(string(sr))
 }
 
 func find(needle string, haystack []*zip.File) *zip.File {