Skip to content

Commit

Permalink
Improved components.
Browse files Browse the repository at this point in the history
  • Loading branch information
petersirka committed Apr 6, 2018
1 parent d59748d commit add9796
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 119 deletions.
9 changes: 8 additions & 1 deletion code/code.js
Expand Up @@ -56,7 +56,14 @@ exports.install = function(instance) {
var fn;

instance.on('data', function(response) {
fn && fn(response.data, instance, response, instance.options, response.repository, require);
if (fn) {
try {
fn(response.data, instance, response, instance.options, response.repository, require);
} catch (e) {
response.data = e;
instance.throw(response);
}
}
});

instance.reconfigure = function() {
Expand Down
41 changes: 0 additions & 41 deletions condition/condition-run.js

This file was deleted.

53 changes: 0 additions & 53 deletions condition/condition.js

This file was deleted.

3 changes: 0 additions & 3 deletions condition/readme.md

This file was deleted.

2 changes: 1 addition & 1 deletion counter/counter.js
Expand Up @@ -44,7 +44,7 @@ exports.install = function(instance) {

instance.custom.status = function() {
setTimeout2(instance.id, function() {
instance.status(count + 'x');
instance.status(count.format(0));
instance.send2(count);
}, 100);
};
Expand Down
17 changes: 5 additions & 12 deletions email/email.js
@@ -1,14 +1,14 @@
exports.id = 'email';
exports.version = '1.3.0';
exports.title = 'Email';
exports.group = 'Notifications';
exports.color = '#8CC152';
exports.input = true;
exports.author = 'Peter Širka';
exports.version = '1.2.0';
exports.output = ['green', 'red'];
exports.output = 1;
exports.icon = 'envelope-o';
exports.dateupdated = '2018-01-19T11:57:00.000Z';
exports.options = { errors: true, type: 'smtp' };
exports.dateupdated = '2018-04-06T09:50:00.000Z';
exports.options = { type: 'smtp' };

exports.html = `<div class="padding">
<div data-jc="dropdown" data-jc-path="type" data-jc-config="required:true;items:@(Internal SMTP)|internal,@(Custom defined SMTP)|smtp" data-jc-value="'smtp'" class="m">@(Sender)</div>
Expand All @@ -33,7 +33,6 @@ exports.html = `<div class="padding">
</div>
</div>
</section>
<div data-jc="checkbox" data-jc-path="errors">@(Enable internal error handling)</div>
<br />
<section>
<label><i class="fa fa-envelope"></i>@(Mail message settings)</label>
Expand Down Expand Up @@ -65,7 +64,6 @@ exports.html = `<div class="padding">
builder.push('');
builder.push('- SMTP: __' + (options.type === 'smtp' ? options.smtp : '@(Internal email)') + '__');
builder.push('- @(authorization): __' + (options.user && options.password ? '@(yes)' : '@(no)') + '__');
builder.push('- @(internal error handling): __' + (options.errors ? '@(yes)' : '@(no)') + '__');
builder.push('---');
builder.push('- @(from): __' + options.from + '__');
builder.push('- @(to): __' + options.target + '__');
Expand All @@ -81,10 +79,6 @@ exports.readme = `# Email sender
You need to configure this component.
__Outputs__:
- \`green\` message has been sent successfully
- \`red\` an error while sending
__Dynamic arguments__:
Are performed via FlowData repository and can be used for subject, from/to addresses or attachments. Use \`repository\` component for creating of dynamic arguments. Examples:
Expand Down Expand Up @@ -151,9 +145,8 @@ exports.install = function(instance) {

message.callback(function(err) {
if (err) {
options.errors && instance.error(err);
msg.data = err;
instance.send2(1, msg);
instance.throw(msg);
} else
instance.send2(0, msg);
});
Expand Down
10 changes: 8 additions & 2 deletions filewriter/filewriter.js
Expand Up @@ -39,9 +39,15 @@ exports.install = function(instance) {
U.queue(instance.id, 1, function(next) {
var line = data instanceof Buffer ? data : typeof(data) === 'string' ? data + delimiter : JSON.stringify(data) + delimiter;
if (instance.options.append)
Fs.appendFile(filename, line, next);
Fs.appendFile(filename, line, function(err) {
err && instance.throw(err);
next();
});
else
Fs.writeFile(filename, line, next);
Fs.writeFile(filename, line, function(err) {
err && instance.throw(err);
next();
});
F.touch('/' + instance.options.filename);
});
};
Expand Down
19 changes: 14 additions & 5 deletions monitorconsumption/monitorconsumption.js
Expand Up @@ -45,7 +45,7 @@ exports.install = function(instance) {
var tproc = null;
var Exec = require('child_process').exec;
var reg_empty = /\s{2,}/g;
var reg_appdisksize = /^[\d\.\,]+/;
var reg_appdisksize = /^[\d.,]+/;

instance.custom.run = function() {

Expand All @@ -60,7 +60,9 @@ exports.install = function(instance) {
instance.options.monitorconsumption && arr.push(function(next) {
Exec('ps -p {0} -o %cpu,rss,etime'.format(process.pid), function(err, response) {

if (!err) {
if (err) {
instance.throw(err);
} else {
var line = response.split('\n')[1];
line = line.trim().replace(reg_empty, ' ').split(' ');
var cpu = line[0].parseFloat();
Expand All @@ -76,15 +78,20 @@ exports.install = function(instance) {
// Get count of open files
instance.options.monitorfiles && arr.push(function(next) {
Exec('lsof -a -p {0} | wc -l'.format(process.pid), function(err, response) {
!err && (current.files = response.trim().parseInt2());
if (err)
instance.throw(err);
else
current.files = response.trim().parseInt2();
next();
});
});

// Get count of opened network connections
instance.options.monitorconnections && arr.push(function(next) {
Exec('netstat -an | grep :{0} | wc -l'.format(F.port), function(err, response) {
if (!err) {
if (err) {
instance.throw(err);
} else {
current.connections = response.trim().parseInt2() - 1;
if (current.connections < 0)
current.connections = 0;
Expand All @@ -96,7 +103,9 @@ exports.install = function(instance) {
// Get directory size
instance.options.monitorsize && current.counter % 5 !== 0 && arr.push(function(next) {
Exec('du -hsb ' + process.cwd(), function(err, response) {
if (!err) {
if (err) {
instance.throw(err);
} else {
var match = response.trim().match(reg_appdisksize);
match && (current.size = match.toString().trim().parseInt2());
}
Expand Down
1 change: 0 additions & 1 deletion templates5.json
Expand Up @@ -5,7 +5,6 @@
"https://rawgit.com/totaljs/flowcomponents/master/code/code.js",
"https://rawgit.com/totaljs/flowcomponents/master/eval/eval.js",
"https://rawgit.com/totaljs/flowcomponents/master/comment/comment.js",
"https://rawgit.com/totaljs/flowcomponents/master/condition/condition.js",
"https://rawgit.com/totaljs/flowcomponents/master/counter/counter.js",
"https://rawgit.com/totaljs/flowcomponents/master/debug/debug.js",
"https://rawgit.com/totaljs/flowcomponents/master/fi/fi.js",
Expand Down

0 comments on commit add9796

Please sign in to comment.