annotate pkg/imports/scheduled.go @ 1985:8eeb0b5eb340

Imports: Made retries and the waiting between the attempts configurable.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 23 Jan 2019 17:58:57 +0100
parents 427f86518097
children d29ac997eb34
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1551
d9eba69f6515 Registered a dummy callback function for scheduled fairway imports in the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 // This is Free Software under GNU Affero General Public License v >= 3.0
d9eba69f6515 Registered a dummy callback function for scheduled fairway imports in the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2 // without warranty, see README.md and license for details.
d9eba69f6515 Registered a dummy callback function for scheduled fairway imports in the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 //
d9eba69f6515 Registered a dummy callback function for scheduled fairway imports in the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 // SPDX-License-Identifier: AGPL-3.0-or-later
d9eba69f6515 Registered a dummy callback function for scheduled fairway imports in the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 // License-Filename: LICENSES/AGPL-3.0.txt
d9eba69f6515 Registered a dummy callback function for scheduled fairway imports in the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 //
d9eba69f6515 Registered a dummy callback function for scheduled fairway imports in the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 // Copyright (C) 2018 by via donau
d9eba69f6515 Registered a dummy callback function for scheduled fairway imports in the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 // – Österreichische Wasserstraßen-Gesellschaft mbH
d9eba69f6515 Registered a dummy callback function for scheduled fairway imports in the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 // Software engineering by Intevation GmbH
d9eba69f6515 Registered a dummy callback function for scheduled fairway imports in the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 //
d9eba69f6515 Registered a dummy callback function for scheduled fairway imports in the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 // Author(s):
d9eba69f6515 Registered a dummy callback function for scheduled fairway imports in the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de>
d9eba69f6515 Registered a dummy callback function for scheduled fairway imports in the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13
d9eba69f6515 Registered a dummy callback function for scheduled fairway imports in the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 package imports
d9eba69f6515 Registered a dummy callback function for scheduled fairway imports in the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15
d9eba69f6515 Registered a dummy callback function for scheduled fairway imports in the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 import (
1748
c11807dc6940 Comfigured imports: Run enqueing of configured imports if triggered by REST with the database connection of the logged in user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1746
diff changeset
17 "context"
c11807dc6940 Comfigured imports: Run enqueing of configured imports if triggered by REST with the database connection of the logged in user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1746
diff changeset
18 "database/sql"
1705
dcbe2a7dc532 Scheduled imports: Take extra configuration parameters from attributes table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1678
diff changeset
19 "errors"
1729
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
20 "fmt"
1551
d9eba69f6515 Registered a dummy callback function for scheduled fairway imports in the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 "log"
1985
8eeb0b5eb340 Imports: Made retries and the waiting between the attempts configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1862
diff changeset
22 "time"
1551
d9eba69f6515 Registered a dummy callback function for scheduled fairway imports in the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23
1661
51a0ba4ede41 Scheduled imports: Made gauge measurement import able to be scheduled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1654
diff changeset
24 "gemma.intevation.de/gemma/pkg/common"
1551
d9eba69f6515 Registered a dummy callback function for scheduled fairway imports in the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 "gemma.intevation.de/gemma/pkg/scheduler"
d9eba69f6515 Registered a dummy callback function for scheduled fairway imports in the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 )
d9eba69f6515 Registered a dummy callback function for scheduled fairway imports in the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27
1729
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
28 // JobKindSetups maps JobKinds to special setup functions.
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
29 var JobKindSetups = map[JobKind]func(*IDConfig) (interface{}, error){
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
30
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
31 GMJobKind: func(cfg *IDConfig) (interface{}, error) {
1665
da0d1a19ebe6 Fairway availability import: Made schedulable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1661
diff changeset
32 log.Println("info: schedule 'gm' import")
1705
dcbe2a7dc532 Scheduled imports: Take extra configuration parameters from attributes table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1678
diff changeset
33 insecure := cfg.Attributes.Bool("insecure")
1665
da0d1a19ebe6 Fairway availability import: Made schedulable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1661
diff changeset
34 return &GaugeMeasurement{
da0d1a19ebe6 Fairway availability import: Made schedulable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1661
diff changeset
35 URL: *cfg.URL,
1705
dcbe2a7dc532 Scheduled imports: Take extra configuration parameters from attributes table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1678
diff changeset
36 Insecure: insecure,
dcbe2a7dc532 Scheduled imports: Take extra configuration parameters from attributes table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1678
diff changeset
37 }, nil
1729
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
38 },
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
39
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
40 FAJobKind: func(cfg *IDConfig) (interface{}, error) {
1665
da0d1a19ebe6 Fairway availability import: Made schedulable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1661
diff changeset
41 log.Println("info: schedule 'fa' import")
1705
dcbe2a7dc532 Scheduled imports: Take extra configuration parameters from attributes table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1678
diff changeset
42 insecure := cfg.Attributes.Bool("insecure")
1665
da0d1a19ebe6 Fairway availability import: Made schedulable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1661
diff changeset
43 return &FairwayAvailability{
da0d1a19ebe6 Fairway availability import: Made schedulable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1661
diff changeset
44 URL: *cfg.URL,
1705
dcbe2a7dc532 Scheduled imports: Take extra configuration parameters from attributes table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1678
diff changeset
45 Insecure: insecure,
dcbe2a7dc532 Scheduled imports: Take extra configuration parameters from attributes table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1678
diff changeset
46 }, nil
1729
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
47 },
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
48
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
49 BNJobKind: func(cfg *IDConfig) (interface{}, error) {
1666
56b29406a163 Bottleneck import: Made schedulable, too. Even if it's not required.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1665
diff changeset
50 log.Println("info: schedule 'bn' import")
1705
dcbe2a7dc532 Scheduled imports: Take extra configuration parameters from attributes table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1678
diff changeset
51 insecure := cfg.Attributes.Bool("insecure")
1666
56b29406a163 Bottleneck import: Made schedulable, too. Even if it's not required.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1665
diff changeset
52 return &Bottleneck{
56b29406a163 Bottleneck import: Made schedulable, too. Even if it's not required.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1665
diff changeset
53 URL: *cfg.URL,
1705
dcbe2a7dc532 Scheduled imports: Take extra configuration parameters from attributes table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1678
diff changeset
54 Insecure: insecure,
dcbe2a7dc532 Scheduled imports: Take extra configuration parameters from attributes table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1678
diff changeset
55 }, nil
1729
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
56 },
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
57
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
58 WXJobKind: func(cfg *IDConfig) (interface{}, error) {
1678
8fdb57173e3f Waterway axis import: Made schedulable, too. TODO: Remove hard-coded parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
59 log.Println("info: schedule 'wx' import")
1705
dcbe2a7dc532 Scheduled imports: Take extra configuration parameters from attributes table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1678
diff changeset
60 ft, found := cfg.Attributes.Get("feature-type")
dcbe2a7dc532 Scheduled imports: Take extra configuration parameters from attributes table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1678
diff changeset
61 if !found {
dcbe2a7dc532 Scheduled imports: Take extra configuration parameters from attributes table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1678
diff changeset
62 return nil, errors.New("cannot find 'feature-type' attribute")
dcbe2a7dc532 Scheduled imports: Take extra configuration parameters from attributes table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1678
diff changeset
63 }
dcbe2a7dc532 Scheduled imports: Take extra configuration parameters from attributes table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1678
diff changeset
64 sb, found := cfg.Attributes.Get("sort-by")
dcbe2a7dc532 Scheduled imports: Take extra configuration parameters from attributes table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1678
diff changeset
65 if !found {
dcbe2a7dc532 Scheduled imports: Take extra configuration parameters from attributes table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1678
diff changeset
66 return nil, errors.New("cannot find 'sort-by' attribute")
dcbe2a7dc532 Scheduled imports: Take extra configuration parameters from attributes table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1678
diff changeset
67 }
1678
8fdb57173e3f Waterway axis import: Made schedulable, too. TODO: Remove hard-coded parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
68 return &WaterwayAxis{
8fdb57173e3f Waterway axis import: Made schedulable, too. TODO: Remove hard-coded parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
69 URL: *cfg.URL,
1705
dcbe2a7dc532 Scheduled imports: Take extra configuration parameters from attributes table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1678
diff changeset
70 FeatureType: ft,
dcbe2a7dc532 Scheduled imports: Take extra configuration parameters from attributes table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1678
diff changeset
71 SortBy: sb,
dcbe2a7dc532 Scheduled imports: Take extra configuration parameters from attributes table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1678
diff changeset
72 }, nil
1729
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
73 },
1785
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1754
diff changeset
74
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1754
diff changeset
75 WAJobKind: func(cfg *IDConfig) (interface{}, error) {
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1754
diff changeset
76 log.Println("info: schedule 'wa' import")
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1754
diff changeset
77 ft, found := cfg.Attributes.Get("feature-type")
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1754
diff changeset
78 if !found {
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1754
diff changeset
79 return nil, errors.New("cannot find 'feature-type' attribute")
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1754
diff changeset
80 }
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1754
diff changeset
81 sb, found := cfg.Attributes.Get("sort-by")
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1754
diff changeset
82 if !found {
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1754
diff changeset
83 return nil, errors.New("cannot find 'sort-by' attribute")
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1754
diff changeset
84 }
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1754
diff changeset
85 return &WaterwayArea{
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1754
diff changeset
86 URL: *cfg.URL,
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1754
diff changeset
87 FeatureType: ft,
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1754
diff changeset
88 SortBy: sb,
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1754
diff changeset
89 }, nil
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1754
diff changeset
90 },
1808
77582da3adb0 Waterway gauges import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1785
diff changeset
91
1856
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
92 FDJobKind: func(cfg *IDConfig) (interface{}, error) {
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
93 log.Println("info: schedule 'fd' import")
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
94 ft, found := cfg.Attributes.Get("feature-type")
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
95 if !found {
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
96 return nil, errors.New("cannot find 'feature-type' attribute")
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
97 }
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
98 sb, found := cfg.Attributes.Get("sort-by")
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
99 if !found {
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
100 return nil, errors.New("cannot find 'sort-by' attribute")
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
101 }
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
102 los, found := cfg.Attributes.Int("los")
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
103 if !found {
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
104 return nil, errors.New("cannot find 'los' attribute")
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
105 }
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
106 minWidth, found := cfg.Attributes.Int("min-width")
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
107 if !found {
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
108 return nil, errors.New("cannot find 'min-width' attribute")
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
109 }
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
110 maxWidth, found := cfg.Attributes.Int("max-width")
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
111 if !found {
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
112 return nil, errors.New("cannot find 'max-width' attribute")
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
113 }
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
114 depth, found := cfg.Attributes.Int("depth")
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
115 if !found {
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
116 return nil, errors.New("cannot find 'depth' attribute")
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
117 }
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
118 sourceOrganization, found := cfg.Attributes.Get("source-organization")
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
119 if !found {
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
120 return nil, errors.New("cannot find 'source-organization' attribute")
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
121 }
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
122
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
123 return &FairwayDimension{
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
124 URL: *cfg.URL,
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
125 FeatureType: ft,
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
126 SortBy: sb,
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
127 LOS: los,
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
128 MinWidth: minWidth,
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
129 MaxWidth: maxWidth,
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
130 Depth: depth,
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
131 SourceOrganization: sourceOrganization,
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
132 }, nil
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
133 },
5996b50d154a Fairway dimension import: Added missing scheduled configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1855
diff changeset
134
1808
77582da3adb0 Waterway gauges import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1785
diff changeset
135 WGJobKind: func(cfg *IDConfig) (interface{}, error) {
77582da3adb0 Waterway gauges import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1785
diff changeset
136 log.Println("info: schedule 'wg' import")
77582da3adb0 Waterway gauges import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1785
diff changeset
137 username, _ := cfg.Attributes.Get("username")
77582da3adb0 Waterway gauges import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1785
diff changeset
138 password, _ := cfg.Attributes.Get("password")
77582da3adb0 Waterway gauges import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1785
diff changeset
139 insecure := cfg.Attributes.Bool("insecure")
77582da3adb0 Waterway gauges import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1785
diff changeset
140 return &WaterwayGauge{
77582da3adb0 Waterway gauges import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1785
diff changeset
141 URL: *cfg.URL,
77582da3adb0 Waterway gauges import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1785
diff changeset
142 Username: username,
77582da3adb0 Waterway gauges import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1785
diff changeset
143 Password: password,
77582da3adb0 Waterway gauges import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1785
diff changeset
144 Insecure: insecure,
77582da3adb0 Waterway gauges import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1785
diff changeset
145 }, nil
77582da3adb0 Waterway gauges import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1785
diff changeset
146 },
1855
bbd653a43a6a Distance marks virtual import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1808
diff changeset
147
bbd653a43a6a Distance marks virtual import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1808
diff changeset
148 DMVJobKind: func(cfg *IDConfig) (interface{}, error) {
bbd653a43a6a Distance marks virtual import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1808
diff changeset
149 log.Println("info: schedule 'dvm' import")
bbd653a43a6a Distance marks virtual import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1808
diff changeset
150 username, _ := cfg.Attributes.Get("username")
bbd653a43a6a Distance marks virtual import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1808
diff changeset
151 password, _ := cfg.Attributes.Get("password")
bbd653a43a6a Distance marks virtual import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1808
diff changeset
152 insecure := cfg.Attributes.Bool("insecure")
bbd653a43a6a Distance marks virtual import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1808
diff changeset
153 return &DistanceMarksVirtual{
bbd653a43a6a Distance marks virtual import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1808
diff changeset
154 URL: *cfg.URL,
bbd653a43a6a Distance marks virtual import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1808
diff changeset
155 Username: username,
bbd653a43a6a Distance marks virtual import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1808
diff changeset
156 Password: password,
bbd653a43a6a Distance marks virtual import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1808
diff changeset
157 Insecure: insecure,
bbd653a43a6a Distance marks virtual import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1808
diff changeset
158 }, nil
bbd653a43a6a Distance marks virtual import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1808
diff changeset
159 },
1862
427f86518097 Added distance marks importer in backend.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1856
diff changeset
160 DMAJobKind: func(cfg *IDConfig) (interface{}, error) {
427f86518097 Added distance marks importer in backend.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1856
diff changeset
161 log.Println("info: schedule 'dma' import")
427f86518097 Added distance marks importer in backend.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1856
diff changeset
162 ft, found := cfg.Attributes.Get("feature-type")
427f86518097 Added distance marks importer in backend.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1856
diff changeset
163 if !found {
427f86518097 Added distance marks importer in backend.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1856
diff changeset
164 return nil, errors.New("cannot find 'feature-type' attribute")
427f86518097 Added distance marks importer in backend.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1856
diff changeset
165 }
427f86518097 Added distance marks importer in backend.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1856
diff changeset
166 sb, found := cfg.Attributes.Get("sort-by")
427f86518097 Added distance marks importer in backend.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1856
diff changeset
167 if !found {
427f86518097 Added distance marks importer in backend.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1856
diff changeset
168 return nil, errors.New("cannot find 'sort-by' attribute")
427f86518097 Added distance marks importer in backend.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1856
diff changeset
169 }
427f86518097 Added distance marks importer in backend.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1856
diff changeset
170 return &DistanceMarksAshore{
427f86518097 Added distance marks importer in backend.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1856
diff changeset
171 URL: *cfg.URL,
427f86518097 Added distance marks importer in backend.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1856
diff changeset
172 FeatureType: ft,
427f86518097 Added distance marks importer in backend.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1856
diff changeset
173 SortBy: sb,
427f86518097 Added distance marks importer in backend.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1856
diff changeset
174 }, nil
427f86518097 Added distance marks importer in backend.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1856
diff changeset
175 },
1551
d9eba69f6515 Registered a dummy callback function for scheduled fairway imports in the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
176 }
d9eba69f6515 Registered a dummy callback function for scheduled fairway imports in the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
177
1729
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
178 func init() {
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
179 run := func(cfgID int64) {
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
180 jobID, err := RunConfiguredImport(cfgID)
1665
da0d1a19ebe6 Fairway availability import: Made schedulable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1661
diff changeset
181 if err != nil {
1729
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
182 log.Printf("error: running scheduled import failed: %v\n", err)
1705
dcbe2a7dc532 Scheduled imports: Take extra configuration parameters from attributes table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1678
diff changeset
183 return
dcbe2a7dc532 Scheduled imports: Take extra configuration parameters from attributes table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1678
diff changeset
184 }
1665
da0d1a19ebe6 Fairway availability import: Made schedulable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1661
diff changeset
185 log.Printf("info: added import #%d to queue\n", jobID)
1661
51a0ba4ede41 Scheduled imports: Made gauge measurement import able to be scheduled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1654
diff changeset
186 }
51a0ba4ede41 Scheduled imports: Made gauge measurement import able to be scheduled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1654
diff changeset
187
1729
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
188 for kind := range JobKindSetups {
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
189 scheduler.RegisterAction(string(kind), run)
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
190 }
1551
d9eba69f6515 Registered a dummy callback function for scheduled fairway imports in the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
191 }
1729
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
192
1748
c11807dc6940 Comfigured imports: Run enqueing of configured imports if triggered by REST with the database connection of the logged in user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1746
diff changeset
193 // RunConfiguredImportContext runs an import configured from the database.
c11807dc6940 Comfigured imports: Run enqueing of configured imports if triggered by REST with the database connection of the logged in user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1746
diff changeset
194 func RunConfiguredImportContext(ctx context.Context, conn *sql.Conn, id int64) (int64, error) {
c11807dc6940 Comfigured imports: Run enqueing of configured imports if triggered by REST with the database connection of the logged in user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1746
diff changeset
195 cfg, err := LoadIDConfigContext(ctx, conn, id)
c11807dc6940 Comfigured imports: Run enqueing of configured imports if triggered by REST with the database connection of the logged in user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1746
diff changeset
196 return runConfiguredImport(id, cfg, err)
c11807dc6940 Comfigured imports: Run enqueing of configured imports if triggered by REST with the database connection of the logged in user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1746
diff changeset
197 }
c11807dc6940 Comfigured imports: Run enqueing of configured imports if triggered by REST with the database connection of the logged in user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1746
diff changeset
198
1729
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
199 // RunConfiguredImport runs an import configured from the database.
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
200 func RunConfiguredImport(id int64) (int64, error) {
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
201 cfg, err := loadIDConfig(id)
1748
c11807dc6940 Comfigured imports: Run enqueing of configured imports if triggered by REST with the database connection of the logged in user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1746
diff changeset
202 return runConfiguredImport(id, cfg, err)
c11807dc6940 Comfigured imports: Run enqueing of configured imports if triggered by REST with the database connection of the logged in user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1746
diff changeset
203 }
c11807dc6940 Comfigured imports: Run enqueing of configured imports if triggered by REST with the database connection of the logged in user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1746
diff changeset
204
c11807dc6940 Comfigured imports: Run enqueing of configured imports if triggered by REST with the database connection of the logged in user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1746
diff changeset
205 func runConfiguredImport(id int64, cfg *IDConfig, err error) (int64, error) {
c11807dc6940 Comfigured imports: Run enqueing of configured imports if triggered by REST with the database connection of the logged in user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1746
diff changeset
206
1729
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
207 if err != nil {
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
208 return 0, err
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
209 }
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
210 if cfg == nil {
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
211 return 0, fmt.Errorf("no config found for id %d.\n", id)
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
212 }
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
213 if cfg.URL == nil {
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
214 return 0, errors.New("error: No URL specified")
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
215 }
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
216
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
217 kind := JobKind(cfg.Kind)
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
218
1746
09f51f2b3b0d Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1729
diff changeset
219 setup := JobKindSetups[kind]
09f51f2b3b0d Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1729
diff changeset
220 if setup == nil {
1729
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
221 return 0, fmt.Errorf("unknown job kind: %s", cfg.Kind)
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
222 }
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
223
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
224 what, err := setup(cfg)
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
225 if err != nil {
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
226 return 0, err
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
227 }
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
228
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
229 var serialized string
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
230 if serialized, err = common.ToJSONString(what); err != nil {
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
231 return 0, err
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
232 }
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
233
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
234 due, _ := cfg.Attributes.Time("due")
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
235
1985
8eeb0b5eb340 Imports: Made retries and the waiting between the attempts configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1862
diff changeset
236 ret, found := cfg.Attributes.Int("retries")
8eeb0b5eb340 Imports: Made retries and the waiting between the attempts configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1862
diff changeset
237 var retries *int
8eeb0b5eb340 Imports: Made retries and the waiting between the attempts configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1862
diff changeset
238 if found {
8eeb0b5eb340 Imports: Made retries and the waiting between the attempts configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1862
diff changeset
239 retries = &ret
8eeb0b5eb340 Imports: Made retries and the waiting between the attempts configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1862
diff changeset
240 }
8eeb0b5eb340 Imports: Made retries and the waiting between the attempts configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1862
diff changeset
241
8eeb0b5eb340 Imports: Made retries and the waiting between the attempts configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1862
diff changeset
242 dur, found := cfg.Attributes.Duration("wait-retry")
8eeb0b5eb340 Imports: Made retries and the waiting between the attempts configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1862
diff changeset
243 var waitRetry *time.Duration
8eeb0b5eb340 Imports: Made retries and the waiting between the attempts configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1862
diff changeset
244 if found {
8eeb0b5eb340 Imports: Made retries and the waiting between the attempts configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1862
diff changeset
245 waitRetry = &dur
1729
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
246 }
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
247
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
248 var jobID int64
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
249 if jobID, err = AddJob(
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
250 kind,
1985
8eeb0b5eb340 Imports: Made retries and the waiting between the attempts configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1862
diff changeset
251 due,
8eeb0b5eb340 Imports: Made retries and the waiting between the attempts configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1862
diff changeset
252 retries,
8eeb0b5eb340 Imports: Made retries and the waiting between the attempts configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1862
diff changeset
253 waitRetry,
1729
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
254 cfg.User,
1754
807569b08513 Import queue: Auto acceptance is now a property of the import kind itself and is not configurable any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1748
diff changeset
255 cfg.SendEMail,
1729
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
256 serialized,
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
257 ); err != nil {
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
258 return 0, err
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
259 }
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
260
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
261 return jobID, nil
74f7d4c531bc Scheduled imports: Refactored calling of database configured import to be reusable elsewhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1708
diff changeset
262 }