Skip to content

Commit 249c281

Browse files
author
Olha Virolainen
authored
bulk query refactoring (#161)
* bulk query refactoring * Delete object use secrets (#162) * bulk_cud.js refactoring (#163) * Lookup objects use secrets (#164) * Triggers use secrets (#165) * polling and query triggers use secrets * lookupObject use secrets (#167) * Fix Unit Tests (#166) * Update dependencies and fix eslint * fix logging sensitive data * refactor circleci * delete mock for platform issue 4527
1 parent 081988e commit 249c281

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+4037
-5602
lines changed

.circleci/build_slug.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

circle.yml renamed to .circleci/config.yml

Lines changed: 1 addition & 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:12-stretch
66
steps:
77
- checkout
88
- restore_cache:

.eslintrc.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module.exports = {
22
env: {
3-
browser: true,
43
commonjs: true,
54
es6: true,
6-
mocha: true
5+
mocha: true,
76
},
87
extends: [
98
'airbnb-base',
109
],
1110
rules: {
12-
'max-len': ["error", { "code": 150 }]
13-
}
11+
'no-await-in-loop': 0,
12+
'max-len': ['error', { code: 150 }],
13+
},
1414
};

Gruntfile.js

Lines changed: 0 additions & 32 deletions
This file was deleted.

component.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,6 @@
143143
}
144144
},
145145
"actions": {
146-
"raw": {
147-
"title": "Raw",
148-
"main": "./lib/actions/raw.js",
149-
"description": "Raw"
150-
},
151146
"queryAction": {
152147
"title": "Query",
153148
"main": "./lib/actions/query.js",

lib/actions/bulk_cud.js

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,27 @@
11
const { messages } = require('elasticio-node');
22
const { Readable } = require('stream');
33
const util = require('../util');
4-
5-
6-
const MetaLoader = require('../helpers/metaLoader');
7-
const sfConnection = require('../helpers/sfConnection.js');
4+
const { callJSForceMethod } = require('../helpers/wrapper');
85

96
const DEFAULT_TIMEOUT = 600; // 10 min
107

11-
128
exports.objectTypes = async function objectTypes(configuration) {
13-
const metaLoader = new MetaLoader(configuration, this);
14-
switch (configuration.sobject) {
9+
switch (configuration.operation) {
1510
case 'insert': {
16-
return metaLoader.getCreateableObjectTypes();
11+
return callJSForceMethod.call(this, configuration, 'getCreateableObjectTypes');
1712
}
1813
case 'update': {
19-
return metaLoader.getUpdateableObjectTypes();
20-
}
21-
case 'upsert': {
22-
return metaLoader.getObjectTypes();
14+
return callJSForceMethod.call(this, configuration, 'getUpdateableObjectTypes');
2315
}
2416
default: {
25-
// 'delete' operation or anything else
26-
return metaLoader.getObjectTypes();
17+
// 'delete' and 'upsert' operation or anything else
18+
return callJSForceMethod.call(this, configuration, 'getObjectTypes');
2719
}
2820
}
2921
};
3022

31-
3223
exports.process = async function bulkCUD(message, configuration) {
33-
this.logger.debug('Starting:', configuration.operation);
34-
35-
const conn = sfConnection.createConnection(configuration, this);
36-
37-
// Bulk operation ('insert', 'update', 'delete', 'upsert')
24+
this.logger.info('Starting Bulk %s action', configuration.operation);
3825
// Get CSV from attachment
3926
if (!message.attachments || Object.keys(message.attachments).length === 0) {
4027
this.logger.error('Attachment not found');
@@ -59,15 +46,19 @@ exports.process = async function bulkCUD(message, configuration) {
5946
if (configuration.operation === 'upsert') {
6047
extra = { extIdField: message.body.extIdField };
6148
}
62-
// Create job
63-
const job = conn.bulk.createJob(configuration.sobject, configuration.operation, extra);
64-
const batch = job.createBatch();
6549

50+
const batchOptions = {
51+
sobject: configuration.sobject,
52+
operation: configuration.operation,
53+
extra,
54+
};
55+
const job = await callJSForceMethod.call(this, configuration, 'bulkCreateJob', batchOptions);
56+
const batch = job.createBatch();
6657
return new Promise((resolve, reject) => {
6758
// Upload CSV to SF
6859
batch.execute(csvStream)
6960
// eslint-disable-next-line no-unused-vars
70-
.on('queue', (batchInfo) => {
61+
.on('queue', () => {
7162
// Check while job status become JobComplete or Failed, Aborted
7263
batch.poll(1000, timeout * 1000);
7364
}).on('response', (rets) => {
@@ -85,7 +76,6 @@ exports.process = async function bulkCUD(message, configuration) {
8576
});
8677
};
8778

88-
8979
exports.getMetaModel = async function getMetaModel(configuration) {
9080
const meta = {
9181
in: {

lib/actions/bulk_q.js

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
const { messages } = require('elasticio-node');
22
const client = require('elasticio-rest-node')();
3-
43
const request = require('request');
5-
6-
const sfConnection = require('../helpers/sfConnection.js');
7-
4+
const { callJSForceMethod } = require('../helpers/wrapper');
85

96
exports.process = async function bulkQuery(message, configuration) {
10-
this.logger.error('Starting: query');
11-
12-
const conn = sfConnection.createConnection(configuration, this);
13-
7+
this.logger.info('Starting Bulk Query action');
148
const signedUrl = await client.resources.storage.createSignedUrl();
15-
169
const out = messages.newEmptyMessage();
1710
out.attachments = {
1811
'bulk_query.csv': {
@@ -21,23 +14,14 @@ exports.process = async function bulkQuery(message, configuration) {
2114
},
2215
};
2316
out.body = {};
24-
17+
const stream = await callJSForceMethod.call(this, configuration, 'bulkQuery', message.body.query);
2518
return new Promise((resolve, reject) => {
26-
// Bulk operation ('query')
27-
const stream = conn.bulk.query(message.body.query)
28-
.on('error', (err) => {
29-
this.logger.debug('error query:', err);
30-
reject(err);
31-
})
32-
.stream();
33-
34-
// upload csv attachment
3519
stream.pipe(request.put(signedUrl.put_url, (err, resp, body) => {
3620
if (err) {
37-
this.logger.debug('error upload:', err);
21+
this.logger.error('Error upload query results');
3822
reject(err);
3923
} else {
40-
this.logger.debug('success');
24+
this.logger.info('Action successfully processed');
4125
out.body = { result: body };
4226
resolve(out);
4327
}

lib/actions/createObject.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ exports.getMetaModel = async function getMetaModel(configuration) {
1313
};
1414

1515
exports.process = async function createObject(message, configuration) {
16-
this.logger.info(`Preparing to create a ${configuration.sobject} object...`);
17-
this.logger.info('Starting Upsert Object Action');
16+
this.logger.info('Starting Create Object Action');
17+
this.logger.debug(`Preparing to create a ${configuration.sobject} object...`);
1818
const binaryField = await attachment.prepareBinaryData(message, configuration, this);
1919

2020
this.logger.info('Sending request to SalesForce...');
2121
const response = await callJSForceMethod.call(this, configuration, 'sobjectCreate', message);
2222

23-
this.logger.debug('SF response: ', response);
24-
this.logger.info(`${configuration.sobject} has been successfully created (ID = ${response.id}).`);
23+
this.logger.debug(`${configuration.sobject} has been successfully created`);
24+
this.logger.trace(`${configuration.sobject} has been successfully created (ID = ${response.id}).`);
2525
// eslint-disable-next-line no-param-reassign
2626
message.body.id = response.id;
2727

0 commit comments

Comments
 (0)