Mercurial > gemma
comparison pkg/imports/scheduled.go @ 1665:da0d1a19ebe6
Fairway availability import: Made schedulable, too.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 23 Dec 2018 13:30:33 +0100 |
parents | pkg/imports/gmsched.go@51a0ba4ede41 |
children | 56b29406a163 |
comparison
equal
deleted
inserted
replaced
1664:819f67c31dfb | 1665:da0d1a19ebe6 |
---|---|
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 imports | |
15 | |
16 import ( | |
17 "log" | |
18 | |
19 "gemma.intevation.de/gemma/pkg/common" | |
20 "gemma.intevation.de/gemma/pkg/scheduler" | |
21 ) | |
22 | |
23 func init() { | |
24 registerAction(GMJobKind, func(cfg *IDConfig) interface{} { | |
25 log.Println("info: schedule 'gm' import") | |
26 return &GaugeMeasurement{ | |
27 URL: *cfg.URL, | |
28 Insecure: false, | |
29 } | |
30 }) | |
31 registerAction(FAJobKind, func(cfg *IDConfig) interface{} { | |
32 log.Println("info: schedule 'fa' import") | |
33 return &FairwayAvailability{ | |
34 URL: *cfg.URL, | |
35 Insecure: false, | |
36 } | |
37 }) | |
38 } | |
39 | |
40 func registerAction(kind JobKind, setup func(cfg *IDConfig) interface{}) { | |
41 | |
42 action := func(id int64) { | |
43 cfg, err := loadIDConfig(id) | |
44 if err != nil { | |
45 log.Printf("error: %v\n", err) | |
46 return | |
47 } | |
48 if cfg == nil { | |
49 log.Printf("error: No config found for id %d.\n", id) | |
50 return | |
51 } | |
52 if cfg.URL == nil { | |
53 log.Println("error: No URL specified") | |
54 return | |
55 } | |
56 | |
57 what := setup(cfg) | |
58 | |
59 var serialized string | |
60 if serialized, err = common.ToJSONString(what); err != nil { | |
61 log.Printf("error: %v\n", err) | |
62 return | |
63 } | |
64 | |
65 var jobID int64 | |
66 if jobID, err = AddJob( | |
67 kind, | |
68 cfg.User, | |
69 cfg.SendEMail, cfg.AutoAccept, | |
70 serialized, | |
71 ); err != nil { | |
72 log.Printf("error: %v\n", err) | |
73 return | |
74 } | |
75 | |
76 log.Printf("info: added import #%d to queue\n", jobID) | |
77 } | |
78 | |
79 scheduler.RegisterAction(string(kind), action) | |
80 } |