@@ -23,6 +23,9 @@ import (
23
23
"sync"
24
24
"time"
25
25
26
+ "crypto/rand"
27
+ "math/big"
28
+
26
29
"github.com/arduino/aws-s3-integration/internal/csv"
27
30
"github.com/arduino/aws-s3-integration/internal/iot"
28
31
"github.com/arduino/aws-s3-integration/internal/s3"
@@ -121,6 +124,17 @@ func (a *TsExtractor) ExportTSToS3(
121
124
return nil
122
125
}
123
126
127
+ func randomRateLimitingSleep () {
128
+ // Random sleep to avoid rate limiting (1s + random(0-500ms))
129
+ n , err := rand .Int (rand .Reader , big .NewInt (500 ))
130
+ if err != nil {
131
+ fmt .Println ("Error:" , err )
132
+ return
133
+ }
134
+ randomSleep := n .Int64 () + 1000
135
+ time .Sleep (time .Duration (randomSleep ) * time .Millisecond )
136
+ }
137
+
124
138
func (a * TsExtractor ) populateNumericTSDataIntoS3 (
125
139
ctx context.Context ,
126
140
from time.Time ,
@@ -144,7 +158,7 @@ func (a *TsExtractor) populateNumericTSDataIntoS3(
144
158
} else {
145
159
// This is due to a rate limit on the IoT API, we need to wait a bit before retrying
146
160
a .logger .Infof ("Rate limit reached for thing %s. Waiting 1 second before retrying.\n " , thingID )
147
- time . Sleep ( 1 * time . Second )
161
+ randomRateLimitingSleep ( )
148
162
}
149
163
}
150
164
if err != nil {
@@ -205,6 +219,9 @@ func extractPropertyNameAndType(thing iotclient.ArduinoThing, propertyID string)
205
219
break
206
220
}
207
221
}
222
+ if propertyType == "STATUS" {
223
+ propertyType = "BOOLEAN"
224
+ }
208
225
return propertyName , propertyType
209
226
}
210
227
@@ -243,7 +260,7 @@ func (a *TsExtractor) populateStringTSDataIntoS3(
243
260
} else {
244
261
// This is due to a rate limit on the IoT API, we need to wait a bit before retrying
245
262
a .logger .Infof ("Rate limit reached for thing %s. Waiting 1 second before retrying.\n " , thingID )
246
- time . Sleep ( 1 * time . Second )
263
+ randomRateLimitingSleep ( )
247
264
}
248
265
}
249
266
if err != nil {
@@ -303,7 +320,7 @@ func (a *TsExtractor) populateRawTSDataIntoS3(
303
320
} else {
304
321
// This is due to a rate limit on the IoT API, we need to wait a bit before retrying
305
322
a .logger .Infof ("Rate limit reached for thing %s. Waiting 1 second before retrying.\n " , thingID )
306
- time . Sleep ( 1 * time . Second )
323
+ randomRateLimitingSleep ( )
307
324
}
308
325
}
309
326
if err != nil {
0 commit comments