Mercurial > gemma
diff pkg/scheduler/scheduler.go @ 1652:f39957ea08aa
Scheduled imports: The configuration id is not optional as it used to load the concrete configuration from the database.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 20 Dec 2018 17:23:54 +0100 |
parents | 2fdd8e57542d |
children | 85386ad17d34 |
line wrap: on
line diff
--- 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