c33howard / signalk-to-timestream

SignalK plugin to publish to Amazon Timestream
Apache License 2.0
0 stars 1 forks source link

Split batch into multiple requests #4

Open cpdk opened 3 years ago

cpdk commented 3 years ago

I have seen issues where no data is flowing to Timestream because more than 100 elements where included in the request. I have fixed it locally using the code below.

Not wanting to push new frameworks I have written a small "unit" test of the _array_chunks method - included here for information - can be executed completely standalone as duplicate of method is also included:

` /*

let testData = [];

for (let i = 0;i < 100;i++) { testData.push("Value #" + i); }

let chunks = _array_chunks(testData, 10);

if (chunks.length != 10) { throw new Error('Unexpected number of chunks'); }

testData.push('One more'); chunks = _array_chunks(testData, 10);

if (chunks.length != 11) { throw new Error('Unexpected number of chunks'); }

if (chunks[10].length != 1) { throw new Error('Unexpected length of last chunk'); }

if (chunks[4][5] != 'Value #45') { throw new Error('Unexpected value found in chunk: ' + chunks[4][5]); }

chunks = _array_chunks(testData, 110);

if (chunks.length != 1) { throw new Error('Unexpected number of chunks - only one expected'); } if (chunks[0].length != 101) { throw new Error('Unexpected length of single chunk'); }

console.log('Test completed'); `

cpdk commented 3 years ago

Interesting - my setup seems very identical to yours - will checkout the new approach.