Skip to content

Commit

Permalink
Fix shared state bug (#78)
Browse files Browse the repository at this point in the history
* Add breaking test.

* Code fix.

* Bump dependencies and node version & apply latest style rules.
  • Loading branch information
jhorbulyk authored Dec 22, 2020
1 parent 12d54cd commit 255e096
Show file tree
Hide file tree
Showing 16 changed files with 1,514 additions and 1,372 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.1.6 (January 4, 2021)
* Fix bug with Write From Array and multiple messages
* Bump node version to 14
* Bump dependencies

## 2.1.5 (October 30, 2020)

Upgrade to sailor 2.6.18
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ This action will convert an incoming array into a CSV file by following approach
Requirements:

* The inbound message is an JSON Array of Objects with identical structure, wrapped by 'inputArray' object;
* 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`.
* 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`.

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

The output of the CSV Write component will be a message with an attachment. In
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
order to access this attachment, the component following the CSV Write must be
able to handle file attachments.

Expand Down
5 changes: 4 additions & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
test:
docker:
- image: circleci/node:8-stretch
- image: circleci/node:14-stretch
steps:
- checkout
- restore_cache:
Expand All @@ -17,6 +17,9 @@ jobs:
- run:
name: Running Mocha Tests
command: npm test
- run:
name: Audit Dependencies
command: npm audit --audit-level=high
workflows:
version: 2
build_and_test:
Expand Down
2 changes: 1 addition & 1 deletion lib/actions/write.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async function ProcessAction(msg, cfg) {

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

if (timeout) {
Expand Down
22 changes: 7 additions & 15 deletions lib/actions/writeFromArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@ const REQUEST_MAX_RETRY = process.env.REQUEST_MAX_RETRY || 7;
const REQUEST_RETRY_DELAY = process.env.REQUEST_RETRY_DELAY || 7000; // 7s
const REQUEST_MAX_CONTENT_LENGTH = process.env.REQUEST_MAX_CONTENT_LENGTH || 10485760; // 10MB

let stringifier;
let signedUrl;
let rowCount = 0;
let ax;
let putUrl;
let options;
async function ProcessAction(msg, cfg) {
let rowCount = 0;

async function init(cfg) {
let delimiter;
switch (cfg.separator) {
case 'comma': {
Expand All @@ -44,20 +39,18 @@ async function init(cfg) {
}
const header = cfg.includeHeaders !== 'No';
logger.trace('Using delimiter: \'%s\'', delimiter);
options = {
const options = {
header,
delimiter,
};

stringifier = csv.stringify(options);
signedUrl = await client.resources.storage.createSignedUrl();
putUrl = signedUrl.put_url;
const stringifier = csv.stringify(options);
const signedUrl = await client.resources.storage.createSignedUrl();
const putUrl = signedUrl.put_url;
logger.trace('Uploading CSV file');
ax = axios.create();
const ax = axios.create();
util.addRetryCountInterceptorToAxios(ax);
}

async function ProcessAction(msg) {
// eslint-disable-next-line consistent-this
const self = this;
const { inputArray } = msg.body;
Expand Down Expand Up @@ -119,4 +112,3 @@ async function ProcessAction(msg) {
}

exports.process = ProcessAction;
exports.init = init;
2 changes: 1 addition & 1 deletion lib/actions/writeFromJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async function ProcessAction(msg, cfg) {

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

if (timeout) {
Expand Down
1 change: 0 additions & 1 deletion lib/triggers/read.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable no-unused-vars,no-param-reassign,class-methods-use-this,no-shadow */


const _ = require('underscore');
const csv = require('csv');
const { messages } = require('elasticio-node');
Expand Down
2 changes: 1 addition & 1 deletion lib/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ exports.addRetryCountInterceptorToAxios = (ax) => {
return Promise.reject(err);
}
config.currentRetryCount += 1;
return new Promise(resolve => setTimeout(() => resolve(ax(config)), config.delay));
return new Promise((resolve) => setTimeout(() => resolve(ax(config)), config.delay));
});
};
Loading

0 comments on commit 255e096

Please sign in to comment.