Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix documentation #43

Merged
merged 13 commits into from
Dec 5, 2019
50 changes: 32 additions & 18 deletions lib/utils/pollingUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SftpPolling extends PollingTrigger {
const formattedEndTime = new Date(endTime);
const fileList = await this.client.list(cfg.directory);
return fileList
.filter((file) => file.type !== 'd')
.filter((file) => new Date(file.modifyTime) >= formattedStartTime)
.filter((file) => new Date(file.modifyTime) < formattedEndTime);
}
Expand All @@ -30,19 +31,25 @@ class SftpPolling extends PollingTrigger {
if (r === null || r === undefined) {
this.logger.trace('Not emitting result with empty body, result was: %j', r);
} else {
// eslint-disable-next-line no-await-in-loop
const attachmentResult = await this.uploadFileAsAttachment(attachmentProcessor, r);
try {
this.logger.debug('Processing file with name: %s, size: %d', r.name, r.size);
// eslint-disable-next-line no-await-in-loop
const attachmentResult = await this.uploadFileAsAttachment(attachmentProcessor, r);

const resultMessage = messages.newMessageWithBody(this.prepareMessageDescription(r));
const resultMessage = messages.newMessageWithBody(this.prepareMessageDescription(r));

resultMessage.attachments[r.name] = {
url: attachmentResult.config.url,
size: r.size,
};
resultMessage.attachments[r.name] = {
url: attachmentResult.config.url,
size: r.size,
};

this.logger.trace('Emitting new message with body: %j', resultMessage.body);
// eslint-disable-next-line no-await-in-loop
await this.context.emit('data', resultMessage);
this.logger.trace('Emitting new message with body: %j', resultMessage.body);
// eslint-disable-next-line no-await-in-loop
await this.context.emit('data', resultMessage);
} catch (e) {
// eslint-disable-next-line no-await-in-loop
await this.context.emit('error', e);
}
}
}
this.logger.debug('Finished emitting data');
Expand All @@ -59,14 +66,21 @@ class SftpPolling extends PollingTrigger {
const resultMessage = messages.newMessageWithBody({ results: [] });
for (let i = 0; i < results.length; i += 1) {
const r = results[i];
// eslint-disable-next-line no-await-in-loop
const attachmentResult = await this.uploadFileAsAttachment(attachmentProcessor, r);
resultMessage.attachments[r.name] = {
url: attachmentResult.config.url,
size: r.size,
};

resultMessage.body.results.push(this.prepareMessageDescription(r));

try {
this.logger.debug('Processing file with name: %s, size: %d', r.name, r.size);
// eslint-disable-next-line no-await-in-loop
const attachmentResult = await this.uploadFileAsAttachment(attachmentProcessor, r);
resultMessage.attachments[r.name] = {
url: attachmentResult.config.url,
size: r.size,
};

resultMessage.body.results.push(this.prepareMessageDescription(r));
} catch (e) {
// eslint-disable-next-line no-await-in-loop
await this.context.emit('error', e);
}
}

this.logger.trace('Emitting new message with body: %j', resultMessage.body);
Expand Down