comparison pkg/scheduler/scheduler.go @ 1540:251ee25accce

Droped on scheduler in favor for a third party library.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 07 Dec 2018 18:34:53 +0100
parents
children 03fcad10104a
comparison
equal deleted inserted replaced
1539:a710d79284e4 1540:251ee25accce
1 // This is Free Software under GNU Affero General Public License v >= 3.0
2 // without warranty, see README.md and license for details.
3 //
4 // SPDX-License-Identifier: AGPL-3.0-or-later
5 // License-Filename: LICENSES/AGPL-3.0.txt
6 //
7 // Copyright (C) 2018 by via donau
8 // – Österreichische Wasserstraßen-Gesellschaft mbH
9 // Software engineering by Intevation GmbH
10 //
11 // Author(s):
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de>
13
14 package scheduler
15
16 import (
17 "errors"
18 "sync"
19
20 "github.com/robfig/cron"
21 )
22
23 var ErrNoSuchAction = errors.New("No such action")
24
25 type funcJob struct {
26 bound bool
27 fn func()
28 }
29
30 type scheduler struct {
31 cr *cron.Cron
32 actions map[string]*funcJob
33 mu sync.Mutex
34 }
35
36 var global = scheduler{
37 cr: cron.New(),
38 actions: make(map[string]*funcJob),
39 }
40
41 func AddAction(name string, fn func()) {
42 global.addAction(name, fn)
43 }
44
45 func AddSchedule(spec, action string) error {
46 return global.addAction(spec, action)
47 }
48
49 func (s *scheduler) addSchedule(spec, action string) error {
50 s.mu.Lock()
51 defer s.mu.Unlock()
52 if s.actions[action] == nil {
53 return ErrNoSuchAction
54 }
55 // TODO: Implement me!
56 }
57
58 func (s *scheduler) addAction(name string, fn func()) {
59 s.mu.Lock()
60 defer s.mu.Unlock()
61 s.actions[name] = &funcJob{fn: fn}
62 }