@@ -31,16 +31,17 @@ type AWSS3ImportTrigger struct {
31
31
}
32
32
33
33
const (
34
- ArduinoPrefix = "/arduino/s3-importer"
35
- IoTApiKey = ArduinoPrefix + "/iot/api-key"
36
- IoTApiSecret = ArduinoPrefix + "/iot/api-secret"
37
- IoTApiOrgId = ArduinoPrefix + "/iot/org-id"
38
- IoTApiTags = ArduinoPrefix + "/iot/filter/tags"
39
- SamplesResoSec = ArduinoPrefix + "/iot/samples-resolution-seconds"
40
- SamplesReso = ArduinoPrefix + "/iot/samples-resolution"
41
- DestinationS3Bucket = ArduinoPrefix + "/destination-bucket"
42
- SamplesResolutionSeconds = 300
43
- TimeExtractionWindowMinutes = 60
34
+ ArduinoPrefix = "/arduino/s3-importer"
35
+ IoTApiKey = ArduinoPrefix + "/iot/api-key"
36
+ IoTApiSecret = ArduinoPrefix + "/iot/api-secret"
37
+ IoTApiOrgId = ArduinoPrefix + "/iot/org-id"
38
+ IoTApiTags = ArduinoPrefix + "/iot/filter/tags"
39
+ SamplesResoSec = ArduinoPrefix + "/iot/samples-resolution-seconds"
40
+ SamplesReso = ArduinoPrefix + "/iot/samples-resolution"
41
+ Scheduling = ArduinoPrefix + "/iot/scheduling"
42
+ DestinationS3Bucket = ArduinoPrefix + "/destination-bucket"
43
+ SamplesResolutionSeconds = 300
44
+ DefaultTimeExtractionWindowMinutes = 60
44
45
)
45
46
46
47
func HandleRequest (ctx context.Context , event * AWSS3ImportTrigger ) (* string , error ) {
@@ -78,6 +79,8 @@ func HandleRequest(ctx context.Context, event *AWSS3ImportTrigger) (*string, err
78
79
if tagsParam != nil {
79
80
tags = tagsParam
80
81
}
82
+
83
+ // Resolve resolution
81
84
resolution , err := paramReader .ReadIntConfig (SamplesResoSec )
82
85
if err != nil {
83
86
// Possibly this parameter is not set. Try SamplesReso
@@ -101,12 +104,29 @@ func HandleRequest(ctx context.Context, event *AWSS3ImportTrigger) (*string, err
101
104
}
102
105
resolution = & val
103
106
}
104
-
105
107
if * resolution > 3600 {
106
108
logger .Errorf ("Resolution %d is invalid" , * resolution )
107
109
return nil , errors .New ("resolution must be between -1 and 3600" )
108
110
}
109
111
112
+ // Resolve scheduling
113
+ schedule , err := paramReader .ReadConfig (Scheduling )
114
+ if err != nil {
115
+ logger .Error ("Error reading parameter " + Scheduling , err )
116
+ return nil , err
117
+ }
118
+ extractionWindowMinutes := DefaultTimeExtractionWindowMinutes
119
+ switch * schedule {
120
+ case "5 minutes" :
121
+ extractionWindowMinutes = 5
122
+ case "15 minutes" :
123
+ extractionWindowMinutes = 15
124
+ case "1 hour" :
125
+ extractionWindowMinutes = 60
126
+ case "1 day" :
127
+ extractionWindowMinutes = 24 * 60
128
+ }
129
+
110
130
logger .Infoln ("------ Running import..." )
111
131
if event .Dev || os .Getenv ("DEV" ) == "true" {
112
132
logger .Infoln ("Running in dev mode" )
@@ -127,8 +147,9 @@ func HandleRequest(ctx context.Context, event *AWSS3ImportTrigger) (*string, err
127
147
} else {
128
148
logger .Infoln ("resolution:" , * resolution , "seconds" )
129
149
}
150
+ logger .Infoln ("data extraction time windows:" , extractionWindowMinutes , "minutes" )
130
151
131
- err = importer .StartImport (ctx , logger , * apikey , * apiSecret , organizationId , tags , * resolution , TimeExtractionWindowMinutes , * destinationS3Bucket )
152
+ err = importer .StartImport (ctx , logger , * apikey , * apiSecret , organizationId , tags , * resolution , extractionWindowMinutes , * destinationS3Bucket )
132
153
if err != nil {
133
154
return nil , err
134
155
}
0 commit comments