Skip to content

Commit 5811c76

Browse files
refactor request/process flows (#12)
* refactor request/process flows * print error and report to monitor in case of uncaught exception * change timeout ot 60 seconds * bump version
1 parent bd864e7 commit 5811c76

File tree

17 files changed

+898
-419
lines changed

17 files changed

+898
-419
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules
1+
node_modules
2+
coverage

.jshintrc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
{
3+
"eqeqeq": true,
4+
"immed": true,
5+
"latedef": "nofunc",
6+
"newcap": false,
7+
"noarg": true,
8+
"sub": true,
9+
"undef": true,
10+
"unused": true,
11+
"boss": true,
12+
"eqnull": true,
13+
"node": true,
14+
"indent": 10,
15+
"esnext": true,
16+
"globals" : {
17+
/* MOCHA */
18+
"describe" : false,
19+
"it" : false,
20+
"before" : false,
21+
"beforeEach" : false,
22+
"after" : false,
23+
"afterEach" : false
24+
}
25+
26+
}

.travis.yml

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

docker-compose.yml

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

example/queueClient.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"use strict";
2+
3+
var Queue = require('../lib/queue');
4+
5+
process.on('uncaughtException', function (err)
6+
{
7+
console.error('Uncaught Exception:' + err.stack);
8+
});
9+
10+
var queue = new Queue("myChannel", {
11+
workers: 50,
12+
servers: ['nats://192.168.99.100:4222'],
13+
timeout: 1000
14+
});
15+
16+
var req = {
17+
field: "myField"
18+
};
19+
20+
21+
for (var i = 0; i < 1; i++){
22+
queue.request(req)
23+
.then(function (res) { // jshint ignore:line
24+
console.log(`finished: ${JSON.stringify(res)}`);
25+
})
26+
.progress(function (info) { // jshint ignore:line
27+
console.log(`progress: ${info.toString()}`);
28+
})
29+
.catch(function (err) { // jshint ignore:line
30+
console.error(`error: ${JSON.stringify(err.toString())}`);
31+
});
32+
}

example/queueServer.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"use strict";
2+
3+
var Queue = require('../lib/queue');
4+
5+
var queue = new Queue("myChannel", {
6+
workers: 50,
7+
servers: ['nats://192.168.99.100:4222']
8+
});
9+
10+
11+
12+
queue.process(function(request, callback){
13+
request.progress("progress");
14+
setTimeout(() => {
15+
console.log(`got request: ${JSON.stringify(request)}`);
16+
callback(null, "ok");
17+
//callback(null, "ok");
18+
request.progress("progress");
19+
}, 4000);
20+
});

gulpfile.js

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
var gulp = require('gulp');
2+
var jshint = require('gulp-jshint');
3+
var rimraf = require('gulp-rimraf');
4+
var env = require('gulp-env');
5+
var runSequence = require('run-sequence');
6+
var fs = require('fs');
7+
var coveralls = require('gulp-coveralls');
8+
var istanbul = require('gulp-istanbul');
9+
var isparta = require('isparta');
10+
var mocha = require('gulp-mocha-co');
11+
require('shelljs/global');
12+
13+
gulp.task('no.onlys', function (callback) {
14+
exec('find . -path "*/*.spec.js" -type f -exec grep -l "describe.only" {} + \n find . -path "*/*.spec.js" -type f -exec grep -l "it.only" {} +', function (code, output) { // jshint ignore:line
15+
if (output) return callback(new Error("The following files contain .only in their tests"));
16+
return callback();
17+
});
18+
});
19+
20+
21+
gulp.task('lint', ['clean'], function () {
22+
return gulp.src(['**/*.js', '!**/node_modules/**', '!**/server/migration/**', '!coverage/**/*.js'])
23+
.pipe(jshint({lookup: true}))
24+
.pipe(jshint.reporter('default'))
25+
.pipe(jshint.reporter('fail'));
26+
});
27+
28+
gulp.task('set_unit_env_vars', function () {
29+
env({
30+
vars: {
31+
}
32+
});
33+
});
34+
35+
gulp.task('unit_pre', function () {
36+
return gulp.src(['**/*.js', '!**/*.spec.js', '!**/node_modules/**/*.js', '!.debug/**/*.js', '!gulpfile.js', '!coverage/**/*.js'])
37+
.pipe(istanbul({ // Covering files
38+
instrumenter: isparta.Instrumenter,
39+
includeUntested: true
40+
}))
41+
.pipe(istanbul.hookRequire()) // Force `require` to return covered files
42+
.on('finish', function () {
43+
gulp.src(['**/*.unit.spec.js', '!**/node_modules/**/*.js'], {read: false})
44+
.pipe(mocha({reporter: 'spec', timeout: '10000'}))
45+
.pipe(istanbul.writeReports({
46+
reporters: ['lcov'],
47+
reportOpts: {dir: 'coverage'}
48+
}))
49+
.once('end', function () {
50+
process.exit();
51+
});
52+
});
53+
});
54+
55+
56+
gulp.task('set_integ_env_vars', function () {
57+
env({
58+
vars: {
59+
}
60+
});
61+
});
62+
63+
gulp.task('integ_pre', function () {
64+
return gulp.src(['**/*.integ.spec.js', '!**/node_modules/**/*.js'], {read: false})
65+
.pipe(mocha({reporter: 'spec', timeout: '10000'}))
66+
.once('end', function () {
67+
process.exit();
68+
});
69+
});
70+
71+
72+
73+
gulp.task('clean', function () {
74+
return gulp.src(['.coverdata', '.debug', '.coverrun'], {read: false})
75+
.pipe(rimraf());
76+
});
77+
78+
79+
gulp.task('unit_test', function (callback) {
80+
runSequence('set_unit_env_vars',
81+
'unit_pre',
82+
callback);
83+
});
84+
85+
gulp.task('integ_test', function (callback) {
86+
runSequence('set_integ_env_vars',
87+
'integ_pre',
88+
callback);
89+
});
90+
91+
gulp.task('coveralls', function (callback) {
92+
var repo_token = process.env.COVERALLS_TOKEN;
93+
if (!repo_token) {
94+
return callback(new Error("COVERALLS_TOKEN environment variable is missing"));
95+
}
96+
else {
97+
fs.writeFile(".coveralls.yml", "service_name: codefresh-io\nrepo_token: " + repo_token, function (err) {
98+
if (err) {
99+
callback(err);
100+
}
101+
else {
102+
gulp.src('coverage/lcov.info')
103+
.pipe(coveralls());
104+
}
105+
});
106+
}
107+
});

0 commit comments

Comments
 (0)