# HG changeset patch # User Sascha L. Teichmann # Date 1545323034 -3600 # Node ID f39957ea08aa782e44b2b067bf851c64a290591f # Parent 8a22d90fb961c167c13a2fc1fa20e7c4f63b00b2 Scheduled imports: The configuration id is not optional as it used to load the concrete configuration from the database. diff -r 8a22d90fb961 -r f39957ea08aa pkg/controllers/importconfig.go --- a/pkg/controllers/importconfig.go Thu Dec 20 17:17:05 2018 +0100 +++ b/pkg/controllers/importconfig.go Thu Dec 20 17:23:54 2018 +0100 @@ -150,7 +150,7 @@ string(importConfig.Kind), cron.String, session.User, - &id, + id, ); err != nil { return } @@ -322,7 +322,7 @@ string(importConfig.Kind), string(*importConfig.Cron), session.User, - &id, + id, ); err != nil { return } diff -r 8a22d90fb961 -r f39957ea08aa pkg/imports/gmsched.go --- a/pkg/imports/gmsched.go Thu Dec 20 17:17:05 2018 +0100 +++ b/pkg/imports/gmsched.go Thu Dec 20 17:23:54 2018 +0100 @@ -23,7 +23,7 @@ scheduler.RegisterAction("gm", scheduledGM) } -func scheduledGM(user string, cfgID *int64) { +func scheduledGM(user string, cfgID int64) { log.Println("info: scheduled GM import") // TODO: Implement me! } diff -r 8a22d90fb961 -r f39957ea08aa pkg/scheduler/boot.go --- a/pkg/scheduler/boot.go Thu Dec 20 17:17:05 2018 +0100 +++ b/pkg/scheduler/boot.go Thu Dec 20 17:23:54 2018 +0100 @@ -63,7 +63,7 @@ ); err != nil { return false, err } - ba.CfgID = &id + ba.CfgID = id return true, nil }) if err != nil { diff -r 8a22d90fb961 -r f39957ea08aa pkg/scheduler/scheduler.go --- a/pkg/scheduler/scheduler.go Thu Dec 20 17:17:05 2018 +0100 +++ b/pkg/scheduler/scheduler.go Thu Dec 20 17:23:54 2018 +0100 @@ -24,14 +24,14 @@ // ErrNoSuchAction if no fitting action was found. var ErrNoSuchAction = errors.New("No such action") -// Action is called with a user and an optional configuration id. -type Action func(user string, cfgID *int64) +// Action is called with a user and a configuration id. +type Action func(user string, cfgID int64) type userAction struct { scheduler *scheduler user string name string - cfgID *int64 + cfgID int64 } type scheduler struct { @@ -66,12 +66,12 @@ // BoundAction is a complete set of infos for // an action to be bound to a user, schedule and -// optional configuration id. +// configuration id. type BoundAction struct { Name string Spec string User string - CfgID *int64 + CfgID int64 } // BootActions setup the global scheduler with a set @@ -117,14 +117,14 @@ } // BindAction binds a named action to a user, a cron spec and -// an optional configuration id. -func BindAction(name, spec, user string, cfgID *int64) error { +// a configuration id. +func BindAction(name, spec, user string, cfgID int64) error { return global.bindAction(name, spec, user, cfgID) } // UnbindAction unbinds a named action from a user and -// an optional configuration id. -func UnbindAction(name, user string, cfgID *int64) { +// a configuration id. +func UnbindAction(name, user string, cfgID int64) { global.unbindAction(name, user, cfgID) } @@ -149,10 +149,6 @@ return s.actions[name] != nil } -func sameCfgID(a, b *int64) bool { - return (a == nil && b == nil) || (a != nil && b != nil && *a == *b) -} - func (s *scheduler) unbindUser(user string) { s.mu.Lock() defer s.mu.Unlock() @@ -195,7 +191,7 @@ var found bool for _, entry := range entries { ua := entry.Job.(*userAction) - if ua.cfgID != nil && *ua.cfgID == cfgID { + if ua.cfgID == cfgID { found = true break } @@ -209,14 +205,14 @@ s.cr = cron.New() for _, entry := range entries { ua := entry.Job.(*userAction) - if ua.cfgID == nil || *ua.cfgID != cfgID { + if ua.cfgID != cfgID { s.cr.Schedule(entry.Schedule, entry.Job) } } s.cr.Start() } -func (s *scheduler) unbindAction(name, user string, cfgID *int64) { +func (s *scheduler) unbindAction(name, user string, cfgID int64) { s.mu.Lock() defer s.mu.Unlock() @@ -225,7 +221,7 @@ var found *userAction for _, entry := range entries { ua := entry.Job.(*userAction) - if ua.name == name && ua.user == user && sameCfgID(cfgID, ua.cfgID) { + if ua.name == name && ua.user == user && cfgID == ua.cfgID { // Already have such a user/action/cfg tuple -> re-schedule. found = ua break @@ -247,7 +243,7 @@ s.cr.Start() } -func (s *scheduler) bindAction(name, spec, user string, cfgID *int64) error { +func (s *scheduler) bindAction(name, spec, user string, cfgID int64) error { schedule, err := cron.Parse(spec) if err != nil { @@ -262,7 +258,7 @@ var found *userAction for _, entry := range entries { ua := entry.Job.(*userAction) - if ua.name == name && ua.user == user && sameCfgID(cfgID, ua.cfgID) { + if ua.name == name && ua.user == user && cfgID == ua.cfgID { // Already have such a user/action/cfg tuple -> re-schedule. found = ua break