Mercurial > gemma
annotate pkg/scheduler/scheduler.go @ 5688:6281c18b109f sr-v2
Finsh serializing v2 meshes.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 12 Feb 2024 02:27:41 +0100 |
parents | 5f47eeea988d |
children |
rev | line source |
---|---|
1540
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 // |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 // |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2018 by via donau |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 // |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 package scheduler |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
3246
64324aaeb1fb
Made logging of waht is registered to the scheduler and the import queue more deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2955
diff
changeset
|
17 "sort" |
64324aaeb1fb
Made logging of waht is registered to the scheduler and the import queue more deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2955
diff
changeset
|
18 "strings" |
1540
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 "sync" |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 |
4411
5826d4de0e40
Workarounds for incompatible upstream updates in pgx and cron packages.
Sascha Wilde <wilde@intevation.de>
parents:
4176
diff
changeset
|
21 cron "gopkg.in/robfig/cron.v1" |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4411
diff
changeset
|
22 |
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4411
diff
changeset
|
23 "gemma.intevation.de/gemma/pkg/log" |
1540
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 ) |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 |
1654
85386ad17d34
Scheduled imports: Don't track the user in the running scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1652
diff
changeset
|
26 // Action is called with a configuration id. |
85386ad17d34
Scheduled imports: Don't track the user in the running scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1652
diff
changeset
|
27 type Action func(cfgID int64) |
1541
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
28 |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
29 type userAction struct { |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
30 scheduler *scheduler |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
31 name string |
1652
f39957ea08aa
Scheduled imports: The configuration id is not optional as it used to load the concrete configuration from the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1590
diff
changeset
|
32 cfgID int64 |
1540
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 } |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 type scheduler struct { |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 cr *cron.Cron |
1541
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
37 actions map[string]Action |
1540
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 mu sync.Mutex |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 } |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 |
1541
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
41 // Run implements cron.Job. |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
42 func (ua *userAction) Run() { |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
43 if a := ua.scheduler.action(ua.name); a != nil { |
1654
85386ad17d34
Scheduled imports: Don't track the user in the running scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1652
diff
changeset
|
44 a(ua.cfgID) |
1556
6869eb94ead2
Don't error if an action is not defined if bound.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1551
diff
changeset
|
45 } else { |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4411
diff
changeset
|
46 log.Warnf("scheduled action '%s' not found.", ua.name) |
1541
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
47 } |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
48 } |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
49 |
1540
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 var global = scheduler{ |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 cr: cron.New(), |
1541
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
52 actions: make(map[string]Action), |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
53 } |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
54 |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
55 // RegisterAction registers a named action to the global scheduler. |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
56 func RegisterAction(name string, action Action) { |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
57 global.registerAction(name, action) |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
58 } |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
59 |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
60 // UnregisterAction ungesiters a named action from the global scheduler. |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
61 func UnregisterAction(name string) { |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
62 global.unregisterAction(name) |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
63 } |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
64 |
1557
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
65 // BoundAction is a complete set of infos for |
1654
85386ad17d34
Scheduled imports: Don't track the user in the running scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1652
diff
changeset
|
66 // an action to be bound to a schedule and |
1652
f39957ea08aa
Scheduled imports: The configuration id is not optional as it used to load the concrete configuration from the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1590
diff
changeset
|
67 // configuration id. |
1557
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
68 type BoundAction struct { |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
69 Name string |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
70 Spec string |
1652
f39957ea08aa
Scheduled imports: The configuration id is not optional as it used to load the concrete configuration from the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1590
diff
changeset
|
71 CfgID int64 |
1557
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
72 } |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
73 |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
74 // BootActions setup the global scheduler with a set |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
75 // of bound actions delivered by the next function. |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
76 func BootActions(next func(*BoundAction) (bool, error)) error { |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
77 return global.bootActions(next) |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
78 } |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
79 |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
80 func (s *scheduler) bootActions(next func(*BoundAction) (bool, error)) error { |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
81 |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
82 cr := cron.New() |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
83 |
2955
e9ff3e8d3c46
Import scheduler: Log number of scheduler jobs to start from database during boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2614
diff
changeset
|
84 var numJobs int |
e9ff3e8d3c46
Import scheduler: Log number of scheduler jobs to start from database during boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2614
diff
changeset
|
85 |
1557
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
86 for { |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
87 var ba BoundAction |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
88 ok, err := next(&ba) |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
89 if err != nil { |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
90 return err |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
91 } |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
92 if !ok { |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
93 break |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
94 } |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
95 schedule, err := cron.Parse(ba.Spec) |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
96 if err != nil { |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
97 return err |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
98 } |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
99 job := &userAction{ |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
100 scheduler: s, |
2614
6691bf76af1c
Booting scheduler: Fixed scheduling import jobs at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1690
diff
changeset
|
101 name: ba.Name, |
1557
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
102 cfgID: ba.CfgID, |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
103 } |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
104 cr.Schedule(schedule, job) |
2955
e9ff3e8d3c46
Import scheduler: Log number of scheduler jobs to start from database during boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2614
diff
changeset
|
105 numJobs++ |
1557
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
106 } |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
107 |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4411
diff
changeset
|
108 log.Infof("booting %d scheduler jobs from database.\n", numJobs) |
2955
e9ff3e8d3c46
Import scheduler: Log number of scheduler jobs to start from database during boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2614
diff
changeset
|
109 |
1557
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
110 s.mu.Lock() |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
111 defer s.mu.Unlock() |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
112 |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
113 s.cr.Stop() |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
114 s.cr = cr |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
115 cr.Start() |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
116 |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
117 return nil |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
118 } |
62171cd9a42b
Import scheduler: Start scheduler a gemma boot time with configurations from database which have a schedule.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1556
diff
changeset
|
119 |
1654
85386ad17d34
Scheduled imports: Don't track the user in the running scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1652
diff
changeset
|
120 // BindAction binds a named action to a cron spec and |
1652
f39957ea08aa
Scheduled imports: The configuration id is not optional as it used to load the concrete configuration from the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1590
diff
changeset
|
121 // a configuration id. |
1654
85386ad17d34
Scheduled imports: Don't track the user in the running scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1652
diff
changeset
|
122 func BindAction(name, spec string, cfgID int64) error { |
85386ad17d34
Scheduled imports: Don't track the user in the running scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1652
diff
changeset
|
123 return global.bindAction(name, spec, cfgID) |
1541
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
124 } |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
125 |
1550
fe633765e05b
Started with JSON model for import configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1544
diff
changeset
|
126 // UnbindAction unbinds a named action from a user and |
1652
f39957ea08aa
Scheduled imports: The configuration id is not optional as it used to load the concrete configuration from the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1590
diff
changeset
|
127 // a configuration id. |
1654
85386ad17d34
Scheduled imports: Don't track the user in the running scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1652
diff
changeset
|
128 func UnbindAction(name string, cfgID int64) { |
85386ad17d34
Scheduled imports: Don't track the user in the running scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1652
diff
changeset
|
129 global.unbindAction(name, cfgID) |
1541
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
130 } |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
131 |
1590
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
132 // UnbindByID unbinds all schedules with a given id. |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
133 func UnbindByID(cfgID int64) { |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
134 global.unbindByID(cfgID) |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
135 } |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
136 |
1689
6caf5cd6249e
WFS: Made golint happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1654
diff
changeset
|
137 // UnbindByIDs unbinds all schedules for a given user. |
1654
85386ad17d34
Scheduled imports: Don't track the user in the running scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1652
diff
changeset
|
138 func UnbindByIDs(ids map[int64]struct{}) { |
85386ad17d34
Scheduled imports: Don't track the user in the running scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1652
diff
changeset
|
139 global.unbindByIDs(ids) |
1544
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
140 } |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
141 |
1550
fe633765e05b
Started with JSON model for import configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1544
diff
changeset
|
142 // HasAction asks if there is an action with a given name. |
fe633765e05b
Started with JSON model for import configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1544
diff
changeset
|
143 func HasAction(name string) bool { |
fe633765e05b
Started with JSON model for import configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1544
diff
changeset
|
144 return global.hasAction(name) |
fe633765e05b
Started with JSON model for import configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1544
diff
changeset
|
145 } |
fe633765e05b
Started with JSON model for import configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1544
diff
changeset
|
146 |
fe633765e05b
Started with JSON model for import configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1544
diff
changeset
|
147 func (s *scheduler) hasAction(name string) bool { |
fe633765e05b
Started with JSON model for import configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1544
diff
changeset
|
148 s.mu.Lock() |
fe633765e05b
Started with JSON model for import configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1544
diff
changeset
|
149 defer s.mu.Unlock() |
fe633765e05b
Started with JSON model for import configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1544
diff
changeset
|
150 return s.actions[name] != nil |
fe633765e05b
Started with JSON model for import configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1544
diff
changeset
|
151 } |
fe633765e05b
Started with JSON model for import configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1544
diff
changeset
|
152 |
1654
85386ad17d34
Scheduled imports: Don't track the user in the running scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1652
diff
changeset
|
153 func (s *scheduler) unbindByIDs(ids map[int64]struct{}) { |
1544
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
154 s.mu.Lock() |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
155 defer s.mu.Unlock() |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
156 |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
157 entries := s.cr.Entries() |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
158 |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
159 if len(entries) == 0 { |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
160 return |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
161 } |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
162 |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
163 var found bool |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
164 for _, entry := range entries { |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
165 ua := entry.Job.(*userAction) |
1654
85386ad17d34
Scheduled imports: Don't track the user in the running scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1652
diff
changeset
|
166 if _, found = ids[ua.cfgID]; found { |
1544
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
167 break |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
168 } |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
169 } |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
170 if !found { |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
171 return |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
172 } |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
173 |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
174 s.cr.Stop() |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
175 s.cr = cron.New() |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
176 for _, entry := range entries { |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
177 ua := entry.Job.(*userAction) |
1654
85386ad17d34
Scheduled imports: Don't track the user in the running scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1652
diff
changeset
|
178 if _, found := ids[ua.cfgID]; !found { |
1544
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
179 s.cr.Schedule(entry.Schedule, entry.Job) |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
180 } |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
181 } |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
182 s.cr.Start() |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
183 } |
5f80ec319a4f
If a user is removed or renamed kill her/his schedule. Needs more case on renaming.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1541
diff
changeset
|
184 |
1590
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
185 func (s *scheduler) unbindByID(cfgID int64) { |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
186 s.mu.Lock() |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
187 defer s.mu.Unlock() |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
188 |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
189 entries := s.cr.Entries() |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
190 |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
191 var found bool |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
192 for _, entry := range entries { |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
193 ua := entry.Job.(*userAction) |
1652
f39957ea08aa
Scheduled imports: The configuration id is not optional as it used to load the concrete configuration from the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1590
diff
changeset
|
194 if ua.cfgID == cfgID { |
1590
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
195 found = true |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
196 break |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
197 } |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
198 } |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
199 |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
200 if !found { |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
201 return |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
202 } |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
203 |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
204 s.cr.Stop() |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
205 s.cr = cron.New() |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
206 for _, entry := range entries { |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
207 ua := entry.Job.(*userAction) |
1652
f39957ea08aa
Scheduled imports: The configuration id is not optional as it used to load the concrete configuration from the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1590
diff
changeset
|
208 if ua.cfgID != cfgID { |
1590
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
209 s.cr.Schedule(entry.Schedule, entry.Job) |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
210 } |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
211 } |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
212 s.cr.Start() |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
213 } |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1557
diff
changeset
|
214 |
1654
85386ad17d34
Scheduled imports: Don't track the user in the running scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1652
diff
changeset
|
215 func (s *scheduler) unbindAction(name string, cfgID int64) { |
1541
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
216 s.mu.Lock() |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
217 defer s.mu.Unlock() |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
218 |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
219 entries := s.cr.Entries() |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
220 |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
221 var found *userAction |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
222 for _, entry := range entries { |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
223 ua := entry.Job.(*userAction) |
1654
85386ad17d34
Scheduled imports: Don't track the user in the running scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1652
diff
changeset
|
224 if ua.name == name && cfgID == ua.cfgID { |
85386ad17d34
Scheduled imports: Don't track the user in the running scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1652
diff
changeset
|
225 // Already have such a action/cfg tuple -> re-schedule. |
1541
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
226 found = ua |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
227 break |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
228 } |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
229 } |
1540
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
230 |
1541
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
231 if found == nil { |
1556
6869eb94ead2
Don't error if an action is not defined if bound.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1551
diff
changeset
|
232 return |
1541
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
233 } |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
234 |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
235 s.cr.Stop() |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
236 s.cr = cron.New() |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
237 for _, entry := range entries { |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
238 ua := entry.Job.(*userAction) |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
239 if ua != found { |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
240 s.cr.Schedule(entry.Schedule, entry.Job) |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
241 } |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
242 } |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
243 s.cr.Start() |
1540
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
244 } |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
245 |
1654
85386ad17d34
Scheduled imports: Don't track the user in the running scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1652
diff
changeset
|
246 func (s *scheduler) bindAction(name, spec string, cfgID int64) error { |
1541
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
247 |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
248 schedule, err := cron.Parse(spec) |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
249 if err != nil { |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
250 return err |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
251 } |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
252 |
1540
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
253 s.mu.Lock() |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
254 defer s.mu.Unlock() |
1541
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
255 |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
256 entries := s.cr.Entries() |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
257 |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
258 var found *userAction |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
259 for _, entry := range entries { |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
260 ua := entry.Job.(*userAction) |
1654
85386ad17d34
Scheduled imports: Don't track the user in the running scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1652
diff
changeset
|
261 if ua.name == name && cfgID == ua.cfgID { |
1541
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
262 // Already have such a user/action/cfg tuple -> re-schedule. |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
263 found = ua |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
264 break |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
265 } |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
266 } |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
267 |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
268 if found == nil { |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
269 // Add to current plan. |
1654
85386ad17d34
Scheduled imports: Don't track the user in the running scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1652
diff
changeset
|
270 job := &userAction{scheduler: s, name: name, cfgID: cfgID} |
1541
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
271 s.cr.Schedule(schedule, job) |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
272 } else { |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
273 // If found re-build all. |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
274 s.cr.Stop() |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
275 s.cr = cron.New() |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
276 for _, entry := range entries { |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
277 ua := entry.Job.(*userAction) |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
278 var sch cron.Schedule |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
279 if found == ua { |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
280 // replace with new schedule. |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
281 sch = schedule |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
282 } else { |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
283 sch = entry.Schedule |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
284 } |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
285 s.cr.Schedule(sch, entry.Job) |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
286 } |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
287 } |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
288 s.cr.Start() |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
289 |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
290 return nil |
1540
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
291 } |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
292 |
1541
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
293 func (s *scheduler) action(name string) Action { |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
294 s.mu.Lock() |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
295 defer s.mu.Unlock() |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
296 return s.actions[name] |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
297 } |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
298 |
4176
c9315a6eb2c2
Made 'golint' and 'staticcheck' happy with scheduler package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3246
diff
changeset
|
299 // LogActionNames logs a sorted list of registered scheduler functions. |
3246
64324aaeb1fb
Made logging of waht is registered to the scheduler and the import queue more deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2955
diff
changeset
|
300 func LogActionNames() { |
64324aaeb1fb
Made logging of waht is registered to the scheduler and the import queue more deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2955
diff
changeset
|
301 names := global.actionNames() |
64324aaeb1fb
Made logging of waht is registered to the scheduler and the import queue more deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2955
diff
changeset
|
302 sort.Strings(names) |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4411
diff
changeset
|
303 log.Infof("actions registered to scheduler: %s\n", |
3246
64324aaeb1fb
Made logging of waht is registered to the scheduler and the import queue more deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2955
diff
changeset
|
304 strings.Join(names, ", ")) |
64324aaeb1fb
Made logging of waht is registered to the scheduler and the import queue more deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2955
diff
changeset
|
305 } |
64324aaeb1fb
Made logging of waht is registered to the scheduler and the import queue more deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2955
diff
changeset
|
306 |
64324aaeb1fb
Made logging of waht is registered to the scheduler and the import queue more deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2955
diff
changeset
|
307 func (s *scheduler) actionNames() []string { |
64324aaeb1fb
Made logging of waht is registered to the scheduler and the import queue more deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2955
diff
changeset
|
308 s.mu.Lock() |
64324aaeb1fb
Made logging of waht is registered to the scheduler and the import queue more deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2955
diff
changeset
|
309 defer s.mu.Unlock() |
64324aaeb1fb
Made logging of waht is registered to the scheduler and the import queue more deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2955
diff
changeset
|
310 names := make([]string, len(s.actions)) |
64324aaeb1fb
Made logging of waht is registered to the scheduler and the import queue more deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2955
diff
changeset
|
311 var i int |
64324aaeb1fb
Made logging of waht is registered to the scheduler and the import queue more deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2955
diff
changeset
|
312 for k := range s.actions { |
64324aaeb1fb
Made logging of waht is registered to the scheduler and the import queue more deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2955
diff
changeset
|
313 names[i] = k |
64324aaeb1fb
Made logging of waht is registered to the scheduler and the import queue more deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2955
diff
changeset
|
314 i++ |
64324aaeb1fb
Made logging of waht is registered to the scheduler and the import queue more deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2955
diff
changeset
|
315 } |
64324aaeb1fb
Made logging of waht is registered to the scheduler and the import queue more deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2955
diff
changeset
|
316 return names |
64324aaeb1fb
Made logging of waht is registered to the scheduler and the import queue more deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2955
diff
changeset
|
317 } |
64324aaeb1fb
Made logging of waht is registered to the scheduler and the import queue more deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2955
diff
changeset
|
318 |
1541
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
319 func (s *scheduler) registerAction(name string, action Action) { |
1540
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
320 s.mu.Lock() |
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
321 defer s.mu.Unlock() |
1541
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
322 s.actions[name] = action |
1540
251ee25accce
Droped on scheduler in favor for a third party library.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
323 } |
1541
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
324 |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
325 func (s *scheduler) unregisterAction(name string) { |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
326 s.mu.Lock() |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
327 defer s.mu.Unlock() |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
328 delete(s.actions, name) |
03fcad10104a
Added an internal cron job executor which binds actions to tuples of cron schedule, user name and an optional configuation id.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1540
diff
changeset
|
329 } |