Skip to content

Commit 255e096

Browse files
authored
Fix shared state bug (#78)
* Add breaking test. * Code fix. * Bump dependencies and node version & apply latest style rules.
1 parent 12d54cd commit 255e096

16 files changed

+1514
-1372
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.1.6 (January 4, 2021)
2+
* Fix bug with Write From Array and multiple messages
3+
* Bump node version to 14
4+
* Bump dependencies
5+
16
## 2.1.5 (October 30, 2020)
27

38
Upgrade to sailor 2.6.18

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ This action will convert an incoming array into a CSV file by following approach
159159
Requirements:
160160

161161
* The inbound message is an JSON Array of Objects with identical structure, wrapped by 'inputArray' object;
162-
* Each JSON object has plain structure without nested levels (structured types `objects` and `arrays` are not supported as values). Only primitive types are supported: `strings`, `numbers`, `booleans` and `null`. Otherwise, the error message will be thrown: `Inbound message should be a plain Object. At least one of entries is not a primitive type`.
162+
* Each JSON object for a message has plain structure without nested levels (structured types `objects` and `arrays` are not supported as values). Only primitive types are supported: `strings`, `numbers`, `booleans` and `null`. Otherwise, the error message will be thrown: `Inbound message should be a plain Object. At least one of entries is not a primitive type`.
163163

164164
The keys of an input JSON will be published as the header in the first row. For each incoming
165165
event, the value for each header will be `stringified` and written as the value
@@ -185,7 +185,7 @@ myfoo2,[1,2]"
185185
,mybar
186186
```
187187

188-
The output of the CSV Write component will be a message with an attachment. In
188+
The output of the CSV Write component will be a message with an attachment. There will be one CSV file generated per incoming message. In
189189
order to access this attachment, the component following the CSV Write must be
190190
able to handle file attachments.
191191

circle.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2
22
jobs:
33
test:
44
docker:
5-
- image: circleci/node:8-stretch
5+
- image: circleci/node:14-stretch
66
steps:
77
- checkout
88
- restore_cache:
@@ -17,6 +17,9 @@ jobs:
1717
- run:
1818
name: Running Mocha Tests
1919
command: npm test
20+
- run:
21+
name: Audit Dependencies
22+
command: npm audit --audit-level=high
2023
workflows:
2124
version: 2
2225
build_and_test:

lib/actions/write.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async function ProcessAction(msg, cfg) {
5050

5151
while (!readyFlag) {
5252
// eslint-disable-next-line no-loop-func,no-await-in-loop
53-
await new Promise(resolve => timeout(resolve, 100));
53+
await new Promise((resolve) => timeout(resolve, 100));
5454
}
5555

5656
if (timeout) {

lib/actions/writeFromArray.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,9 @@ const REQUEST_MAX_RETRY = process.env.REQUEST_MAX_RETRY || 7;
1212
const REQUEST_RETRY_DELAY = process.env.REQUEST_RETRY_DELAY || 7000; // 7s
1313
const REQUEST_MAX_CONTENT_LENGTH = process.env.REQUEST_MAX_CONTENT_LENGTH || 10485760; // 10MB
1414

15-
let stringifier;
16-
let signedUrl;
17-
let rowCount = 0;
18-
let ax;
19-
let putUrl;
20-
let options;
15+
async function ProcessAction(msg, cfg) {
16+
let rowCount = 0;
2117

22-
async function init(cfg) {
2318
let delimiter;
2419
switch (cfg.separator) {
2520
case 'comma': {
@@ -44,20 +39,18 @@ async function init(cfg) {
4439
}
4540
const header = cfg.includeHeaders !== 'No';
4641
logger.trace('Using delimiter: \'%s\'', delimiter);
47-
options = {
42+
const options = {
4843
header,
4944
delimiter,
5045
};
5146

52-
stringifier = csv.stringify(options);
53-
signedUrl = await client.resources.storage.createSignedUrl();
54-
putUrl = signedUrl.put_url;
47+
const stringifier = csv.stringify(options);
48+
const signedUrl = await client.resources.storage.createSignedUrl();
49+
const putUrl = signedUrl.put_url;
5550
logger.trace('Uploading CSV file');
56-
ax = axios.create();
51+
const ax = axios.create();
5752
util.addRetryCountInterceptorToAxios(ax);
58-
}
5953

60-
async function ProcessAction(msg) {
6154
// eslint-disable-next-line consistent-this
6255
const self = this;
6356
const { inputArray } = msg.body;
@@ -119,4 +112,3 @@ async function ProcessAction(msg) {
119112
}
120113

121114
exports.process = ProcessAction;
122-
exports.init = init;

lib/actions/writeFromJson.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ async function ProcessAction(msg, cfg) {
7878

7979
while (!readyFlag) {
8080
// eslint-disable-next-line no-loop-func,no-await-in-loop
81-
await new Promise(resolve => timeout(resolve, 100));
81+
await new Promise((resolve) => timeout(resolve, 100));
8282
}
8383

8484
if (timeout) {

lib/triggers/read.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* eslint-disable no-unused-vars,no-param-reassign,class-methods-use-this,no-shadow */
22

3-
43
const _ = require('underscore');
54
const csv = require('csv');
65
const { messages } = require('elasticio-node');

lib/util/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ exports.addRetryCountInterceptorToAxios = (ax) => {
77
return Promise.reject(err);
88
}
99
config.currentRetryCount += 1;
10-
return new Promise(resolve => setTimeout(() => resolve(ax(config)), config.delay));
10+
return new Promise((resolve) => setTimeout(() => resolve(ax(config)), config.delay));
1111
});
1212
};

0 commit comments

Comments
 (0)