# HG changeset patch # User Sascha L. Teichmann # Date 1547133566 -3600 # Node ID 807569b08513b0693e7761a01acd9a2aabf35e9c # Parent 68bd990dd8e517eb6198c1719fdbd6dd88381713 Import queue: Auto acceptance is now a property of the import kind itself and is not configurable any more. diff -r 68bd990dd8e5 -r 807569b08513 pkg/controllers/agmimports.go --- a/pkg/controllers/agmimports.go Thu Jan 10 15:55:08 2019 +0100 +++ b/pkg/controllers/agmimports.go Thu Jan 10 16:19:26 2019 +0100 @@ -115,7 +115,7 @@ imports.AGMJobKind, due, retries, session.User, - sendEmail, false, + sendEmail, serialized) if err != nil { diff -r 68bd990dd8e5 -r 807569b08513 pkg/controllers/importconfig.go --- a/pkg/controllers/importconfig.go Thu Jan 10 15:55:08 2019 +0100 +++ b/pkg/controllers/importconfig.go Thu Jan 10 16:19:26 2019 +0100 @@ -37,7 +37,6 @@ username, kind, send_email, - auto_accept, cron, url FROM waterway.import_configuration` @@ -50,7 +49,7 @@ insertImportConfigurationSQL = ` INSERT INTO waterway.import_configuration -(username, kind, cron, send_email, auto_accept, url) +(username, kind, cron, send_email, url) VALUES ($1, $2, $3, $4, $5, $6) RETURNING id` @@ -78,7 +77,6 @@ cron = $4, url = $5, send_email = $6, - auto_accept = $7 WHERE id = $1 ` ) @@ -142,7 +140,6 @@ &entry.User, &kind, &entry.SendEMail, - &entry.AutoAccept, &dummy, &url, ) @@ -161,7 +158,6 @@ session, _ := auth.GetSession(req) entry.SendEMail = importConfig.SendEMail - entry.AutoAccept = importConfig.AutoAccept // We always take the cron spec from the input. // If there is no spec remove schedule. @@ -181,7 +177,6 @@ cron, url, importConfig.SendEMail, - importConfig.AutoAccept, ); err != nil { return } @@ -372,7 +367,6 @@ string(importConfig.Kind), cron, importConfig.SendEMail, - importConfig.AutoAccept, url, ).Scan(&id); err != nil { return @@ -440,7 +434,6 @@ &entry.User, &kind, &entry.SendEMail, - &entry.AutoAccept, &cron, &url, ); err != nil { diff -r 68bd990dd8e5 -r 807569b08513 pkg/controllers/manualimports.go --- a/pkg/controllers/manualimports.go Thu Jan 10 15:55:08 2019 +0100 +++ b/pkg/controllers/manualimports.go Thu Jan 10 16:19:26 2019 +0100 @@ -35,37 +35,37 @@ return due, retries } -func importBottleneck(input interface{}) (interface{}, time.Time, int, bool, bool) { +func importBottleneck(input interface{}) (interface{}, time.Time, int, bool) { bi := input.(*models.BottleneckImport) bn := &imports.Bottleneck{ URL: bi.URL, Insecure: bi.Insecure, } due, retries := retry(bi.Attributes) - return bn, due, retries, bi.SendEmail, false + return bn, due, retries, bi.SendEmail } -func importGaugeMeasurement(input interface{}) (interface{}, time.Time, int, bool, bool) { +func importGaugeMeasurement(input interface{}) (interface{}, time.Time, int, bool) { gi := input.(*models.GaugeMeasurementImport) gm := &imports.GaugeMeasurement{ URL: gi.URL, Insecure: gi.Insecure, } due, retries := retry(gi.Attributes) - return gm, due, retries, gi.SendEmail, true + return gm, due, retries, gi.SendEmail } -func importFairwayAvailability(input interface{}) (interface{}, time.Time, int, bool, bool) { +func importFairwayAvailability(input interface{}) (interface{}, time.Time, int, bool) { fai := input.(*models.FairwayAvailabilityImport) fa := &imports.FairwayAvailability{ URL: fai.URL, Insecure: fai.Insecure, } due, retries := retry(fai.Attributes) - return fa, due, retries, fai.SendEmail, true + return fa, due, retries, fai.SendEmail } -func importWaterwayAxis(input interface{}) (interface{}, time.Time, int, bool, bool) { +func importWaterwayAxis(input interface{}) (interface{}, time.Time, int, bool) { wxi := input.(*models.WaterwayAxisImport) wx := &imports.WaterwayAxis{ URL: wxi.URL, @@ -73,18 +73,18 @@ SortBy: wxi.SortBy, } due, retries := retry(wxi.Attributes) - return wx, due, retries, wxi.SendEmail, true + return wx, due, retries, wxi.SendEmail } func manualImport( kind imports.JobKind, - setup func(interface{}) (interface{}, time.Time, int, bool, bool), + setup func(interface{}) (interface{}, time.Time, int, bool), ) func(interface{}, *http.Request, *sql.Conn) (JSONResult, error) { return func(input interface{}, req *http.Request, _ *sql.Conn) ( jr JSONResult, err error) { - what, due, retries, sendEmail, autoAccept := setup(input) + what, due, retries, sendEmail := setup(input) var serialized string if serialized, err = common.ToJSONString(what); err != nil { @@ -98,7 +98,7 @@ kind, due, retries, session.User, - sendEmail, autoAccept, + sendEmail, serialized, ); err != nil { return diff -r 68bd990dd8e5 -r 807569b08513 pkg/controllers/srimports.go --- a/pkg/controllers/srimports.go Thu Jan 10 15:55:08 2019 +0100 +++ b/pkg/controllers/srimports.go Thu Jan 10 16:19:26 2019 +0100 @@ -184,7 +184,7 @@ imports.SRJobKind, due, retries, session.User, - sendEmail, false, + sendEmail, serialized) if err != nil { diff -r 68bd990dd8e5 -r 807569b08513 pkg/imports/agm.go --- a/pkg/imports/agm.go Thu Jan 10 15:55:08 2019 +0100 +++ b/pkg/imports/agm.go Thu Jan 10 16:19:26 2019 +0100 @@ -38,6 +38,8 @@ RegisterJobCreator(AGMJobKind, agmJobCreator{}) } +func (agmJobCreator) AutoAccept() bool { return false } + func (agmJobCreator) Description() string { return "approved gauge measurements" } diff -r 68bd990dd8e5 -r 807569b08513 pkg/imports/bn.go --- a/pkg/imports/bn.go Thu Jan 10 15:55:08 2019 +0100 +++ b/pkg/imports/bn.go Thu Jan 10 16:19:26 2019 +0100 @@ -85,9 +85,9 @@ RegisterJobCreator(BNJobKind, bnJobCreator{}) } -func (bnJobCreator) Description() string { - return "bottlenecks" -} +func (bnJobCreator) Description() string { return "bottlenecks" } + +func (bnJobCreator) AutoAccept() bool { return false } func (bnJobCreator) Create(_ JobKind, data string) (Job, error) { bn := new(Bottleneck) diff -r 68bd990dd8e5 -r 807569b08513 pkg/imports/config.go --- a/pkg/imports/config.go Thu Jan 10 15:55:08 2019 +0100 +++ b/pkg/imports/config.go Thu Jan 10 16:19:26 2019 +0100 @@ -41,10 +41,6 @@ // when the import was changed to states // 'pending' or 'failed'. SendEMail bool `json:"send-email"` - // AutoAccept indicates that an import - // automatically will change from state - // 'pending' to state 'accepted'. - AutoAccept bool `json:"auto-accept"` // Cron is the cron schedule // of this configuration if this value is not // nil. If nil the import is not scheduled. @@ -62,7 +58,6 @@ User string `json:"user"` Kind ImportKind `json:"kind"` SendEMail bool `json:"send-email"` - AutoAccept bool `json:"auto-accept"` Cron *CronSpec `json:"cron,omitempty"` URL *string `json:"url,omitempty"` Attributes common.Attributes `json:"attributes,omitempty"` @@ -109,7 +104,6 @@ username, kind, send_email, - auto_accept, cron, url FROM waterway.import_configuration @@ -131,7 +125,6 @@ &cfg.User, &kind, &cfg.SendEMail, - &cfg.AutoAccept, &cron, &url, ) diff -r 68bd990dd8e5 -r 807569b08513 pkg/imports/fa.go --- a/pkg/imports/fa.go Thu Jan 10 15:55:08 2019 +0100 +++ b/pkg/imports/fa.go Thu Jan 10 16:19:26 2019 +0100 @@ -157,6 +157,8 @@ } } +func (faJobCreator) AutoAccept() bool { return true } + // StageDone moves the imported fairway availablities out of the staging area. // Currently doing nothing. func (faJobCreator) StageDone(context.Context, *sql.Tx, int64) error { diff -r 68bd990dd8e5 -r 807569b08513 pkg/imports/gm.go --- a/pkg/imports/gm.go Thu Jan 10 15:55:08 2019 +0100 +++ b/pkg/imports/gm.go Thu Jan 10 16:19:26 2019 +0100 @@ -104,6 +104,8 @@ } } +func (gmJobCreator) AutoAccept() bool { return true } + // StageDone moves the imported gauge measurement out of the staging area. // Currently doing nothing. func (gmJobCreator) StageDone(context.Context, *sql.Tx, int64) error { diff -r 68bd990dd8e5 -r 807569b08513 pkg/imports/queue.go --- a/pkg/imports/queue.go Thu Jan 10 15:55:08 2019 +0100 +++ b/pkg/imports/queue.go Thu Jan 10 16:19:26 2019 +0100 @@ -91,16 +91,18 @@ // (state = accepted). This can be used to finalize the imported // data to move it e.g from the staging area. StageDone(context.Context, *sql.Tx, int64) error + // AutoAccept indicates that imports of this kind + // don't need a review. + AutoAccept() bool } idJob struct { - id int64 - kind JobKind - user string - trysLeft sql.NullInt64 - sendEmail bool - autoAccept bool - data string + id int64 + kind JobKind + user string + trysLeft sql.NullInt64 + sendEmail bool + data string } ) @@ -145,7 +147,6 @@ trys_left, username, send_email, - auto_accept, data ) VALUES ( $1, @@ -154,7 +155,6 @@ $4, $5, $6, - $7 ) RETURNING id` selectJobSQL = ` @@ -164,7 +164,6 @@ trys_left, username, send_email, - auto_accept, data FROM waterway.imports WHERE @@ -275,7 +274,7 @@ due time.Time, trysLeft int, user string, - sendEmail, autoAccept bool, + sendEmail bool, data string, ) (int64, error) { ctx := context.Background() @@ -296,7 +295,6 @@ tl, user, sendEmail, - autoAccept, data).Scan(&id) }) if err == nil { @@ -317,10 +315,10 @@ due time.Time, trysLeft int, user string, - sendEmail, autoAccept bool, + sendEmail bool, data string, ) (int64, error) { - return iqueue.addJob(kind, due, trysLeft, user, sendEmail, autoAccept, data) + return iqueue.addJob(kind, due, trysLeft, user, sendEmail, data) } type logFeedback int64 @@ -407,7 +405,6 @@ &ji.trysLeft, &ji.user, &ji.sendEmail, - &ji.autoAccept, &ji.data, ); err != nil { return err @@ -571,7 +568,7 @@ switch { case errDo != nil || errCleanup != nil: state = "failed" - case idj.autoAccept: + case jc.AutoAccept(): state = "accepted" default: state = "pending" @@ -588,7 +585,7 @@ nid, err := q.addJob( idj.kind, retry.When, idj.trys(), - idj.user, idj.sendEmail, idj.autoAccept, + idj.user, idj.sendEmail, idj.data) if err != nil { log.Printf("error: retry enqueue failed: %v\n", err) diff -r 68bd990dd8e5 -r 807569b08513 pkg/imports/scheduled.go --- a/pkg/imports/scheduled.go Thu Jan 10 15:55:08 2019 +0100 +++ b/pkg/imports/scheduled.go Thu Jan 10 16:19:26 2019 +0100 @@ -140,7 +140,7 @@ kind, due, retries, cfg.User, - cfg.SendEMail, cfg.AutoAccept, + cfg.SendEMail, serialized, ); err != nil { return 0, err diff -r 68bd990dd8e5 -r 807569b08513 pkg/imports/sr.go --- a/pkg/imports/sr.go Thu Jan 10 15:55:08 2019 +0100 +++ b/pkg/imports/sr.go Thu Jan 10 16:19:26 2019 +0100 @@ -73,9 +73,9 @@ RegisterJobCreator(SRJobKind, srJobCreator{}) } -func (srJobCreator) Description() string { - return "sounding results" -} +func (srJobCreator) Description() string { return "sounding results" } + +func (srJobCreator) AutoAccept() bool { return false } func (srJobCreator) Create(_ JobKind, data string) (Job, error) { sr := new(SoundingResult) diff -r 68bd990dd8e5 -r 807569b08513 pkg/imports/wx.go --- a/pkg/imports/wx.go Thu Jan 10 15:55:08 2019 +0100 +++ b/pkg/imports/wx.go Thu Jan 10 16:19:26 2019 +0100 @@ -52,9 +52,9 @@ RegisterJobCreator(WXJobKind, wxJobCreator{}) } -func (wxJobCreator) Description() string { - return "waterway axis" -} +func (wxJobCreator) Description() string { return "waterway axis" } + +func (wxJobCreator) AutoAccept() bool { return true } func (wxJobCreator) Create(_ JobKind, data string) (Job, error) { wx := new(WaterwayAxis) diff -r 68bd990dd8e5 -r 807569b08513 schema/gemma.sql --- a/schema/gemma.sql Thu Jan 10 15:55:08 2019 +0100 +++ b/schema/gemma.sql Thu Jan 10 16:19:26 2019 +0100 @@ -559,7 +559,6 @@ ON UPDATE CASCADE, kind varchar NOT NULL, send_email boolean NOT NULL DEFAULT false, - auto_accept boolean NOT NULL DEFAULT false, cron varchar, url varchar )