Mercurial > gemma
changeset 2016:25967829cf00 unify_imports
Started to simplify the import models.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 24 Jan 2019 17:14:10 +0100 |
parents | 917c672591c2 |
children | 1324dd12af9e |
files | pkg/controllers/importconfig.go pkg/imports/config.go pkg/imports/fa.go pkg/models/bn.go pkg/models/importbase.go pkg/models/imports.go |
diffstat | 6 files changed, 105 insertions(+), 55 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/controllers/importconfig.go Thu Jan 24 16:17:37 2019 +0100 +++ b/pkg/controllers/importconfig.go Thu Jan 24 17:14:10 2019 +0100 @@ -27,6 +27,7 @@ "gemma.intevation.de/gemma/pkg/auth" "gemma.intevation.de/gemma/pkg/common" "gemma.intevation.de/gemma/pkg/imports" + "gemma.intevation.de/gemma/pkg/models" "gemma.intevation.de/gemma/pkg/scheduler" ) @@ -441,7 +442,7 @@ } entry.Kind = imports.ImportKind(kind) if cron.Valid { - cs := imports.CronSpec(cron.String) + cs := models.CronSpec(cron.String) entry.Cron = &cs } if url.Valid {
--- a/pkg/imports/config.go Thu Jan 24 16:17:37 2019 +0100 +++ b/pkg/imports/config.go Thu Jan 24 17:14:10 2019 +0100 @@ -19,16 +19,12 @@ "encoding/json" "fmt" - "github.com/robfig/cron" - "gemma.intevation.de/gemma/pkg/auth" "gemma.intevation.de/gemma/pkg/common" + "gemma.intevation.de/gemma/pkg/models" ) type ( - // CronSpec is a string containing a cron line. - CronSpec string - // ImportKind is a string which has to be one // of the registered import types. ImportKind string @@ -44,7 +40,7 @@ // Cron is the cron schedule // of this configuration if this value is not // nil. If nil the import is not scheduled. - Cron *CronSpec `json:"cron"` + Cron *models.CronSpec `json:"cron"` // URL is an optional URL used by the import. URL *string `json:"url"` // Attributes are optional key/value pairs for a configuration. @@ -58,7 +54,7 @@ User string `json:"user"` Kind ImportKind `json:"kind"` SendEMail bool `json:"send-email"` - Cron *CronSpec `json:"cron,omitempty"` + Cron *models.CronSpec `json:"cron,omitempty"` URL *string `json:"url,omitempty"` Attributes common.Attributes `json:"attributes,omitempty"` } @@ -81,21 +77,6 @@ return nil } -// UnmarshalJSON checks if the incoming string is -// a valid cron line. -func (cs *CronSpec) UnmarshalJSON(data []byte) error { - var spec string - if err := json.Unmarshal(data, &spec); err != nil { - return err - } - if _, err := cron.Parse(spec); err != nil { - return err - } - *cs = CronSpec(spec) - - return nil -} - const ( configUser = "sys_admin" @@ -138,7 +119,7 @@ cfg.Kind = ImportKind(kind) if cron.Valid { - c := CronSpec(cron.String) + c := models.CronSpec(cron.String) cfg.Cron = &c } if url.Valid {
--- a/pkg/imports/fa.go Thu Jan 24 16:17:37 2019 +0100 +++ b/pkg/imports/fa.go Thu Jan 24 17:14:10 2019 +0100 @@ -182,6 +182,11 @@ // CleanUp of a fairway availablities import is a NOP. func (*FairwayAvailability) CleanUp() error { return nil } +type bottleneckCountry struct { + ID string + ResponsibleCountry string +} + // Do executes the actual fairway availability import. func (fa *FairwayAvailability) Do( ctx context.Context, @@ -199,10 +204,10 @@ } defer rows.Close() - bottlenecks := []models.Bottleneck{} + bottlenecks := []bottleneckCountry{} for rows.Next() { - var bn models.Bottleneck + var bn bottleneckCountry if err = rows.Scan( &bn.ID, &bn.ResponsibleCountry, @@ -274,7 +279,7 @@ func (fa *FairwayAvailability) doForFAs( ctx context.Context, - bottlenecks []models.Bottleneck, + bottlenecks []bottleneckCountry, fairwayAvailabilities map[models.UniqueFairwayAvailability]int64, latestDate pgtype.Timestamp, conn *sql.Conn,
--- a/pkg/models/bn.go Thu Jan 24 16:17:37 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -// This is Free Software under GNU Affero General Public License v >= 3.0 -// without warranty, see README.md and license for details. -// -// SPDX-License-Identifier: AGPL-3.0-or-later -// License-Filename: LICENSES/AGPL-3.0.txt -// -// Copyright (C) 2018 by via donau -// – Österreichische Wasserstraßen-Gesellschaft mbH -// Software engineering by Intevation GmbH -// -// Author(s): -// * Sascha L. Teichmann <sascha.teichmann@intevation.de> - -package models - -import "gemma.intevation.de/gemma/pkg/common" - -type BottleneckImport struct { - URL string `json:"url"` - Insecure bool `json:"insecure"` - SendEmail bool `json:"send-email"` - Attributes common.Attributes `json:"attributes,omitempty"` -} - -type Bottleneck struct { - ID string - ResponsibleCountry string -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pkg/models/importbase.go Thu Jan 24 17:14:10 2019 +0100 @@ -0,0 +1,69 @@ +// This is Free Software under GNU Affero General Public License v >= 3.0 +// without warranty, see README.md and license for details. +// +// SPDX-License-Identifier: AGPL-3.0-or-later +// License-Filename: LICENSES/AGPL-3.0.txt +// +// Copyright (C) 2018 by via donau +// – Österreichische Wasserstraßen-Gesellschaft mbH +// Software engineering by Intevation GmbH +// +// Author(s): +// * Sascha L. Teichmann <sascha.teichmann@intevation.de> + +package models + +import ( + "encoding/json" + "time" + + "github.com/robfig/cron" +) + +type ( + // CronSpec is a string containing a cron line. + CronSpec string + + QueueConfigurationType struct { + Trys *int `json:"trys,omitempty"` + WaitRetry *time.Duration `json:"wait-retry,omitempty"` + Cron *CronSpec `json:"cron,omitempty"` + EMail bool `json:"send-email,omitempty"` + } + + QueueConfigurationGetter interface { + GetQueueConfiguration() *QueueConfigurationType + } + + URLType struct { + URL string `json:"url"` + Insecure bool `json:"insecure,omitempty"` + User *string `json:"user,omitempty"` + Password *string `json:"password,omitempty"` + } + + URLTypeGetter interface { + GetURLType() *URLType + } +) + +func (qct *QueueConfigurationType) GetQueueConfiguration() *QueueConfigurationType { + return qct +} + +func (ut *URLType) GetURLType() *URLType { + return ut +} + +// UnmarshalJSON checks if the incoming string is a valid cron line. +func (cs *CronSpec) UnmarshalJSON(data []byte) error { + var spec string + if err := json.Unmarshal(data, &spec); err != nil { + return err + } + if _, err := cron.Parse(spec); err != nil { + return err + } + *cs = CronSpec(spec) + return nil +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pkg/models/imports.go Thu Jan 24 17:14:10 2019 +0100 @@ -0,0 +1,22 @@ +// This is Free Software under GNU Affero General Public License v >= 3.0 +// without warranty, see README.md and license for details. +// +// SPDX-License-Identifier: AGPL-3.0-or-later +// License-Filename: LICENSES/AGPL-3.0.txt +// +// Copyright (C) 2018 by via donau +// – Österreichische Wasserstraßen-Gesellschaft mbH +// Software engineering by Intevation GmbH +// +// Author(s): +// * Sascha L. Teichmann <sascha.teichmann@intevation.de> +package models + +import "gemma.intevation.de/gemma/pkg/common" + +type BottleneckImport struct { + URL string `json:"url"` + Insecure bool `json:"insecure"` + SendEmail bool `json:"send-email"` + Attributes common.Attributes `json:"attributes,omitempty"` +}