Skip to content

Commit

Permalink
Updated dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardonunesdev committed Sep 9, 2018
1 parent aeb0769 commit bf581fb
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 3 deletions.
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -25,15 +25,15 @@
"node": ">=4.0.0"
},
"dependencies": {
"bluebird": "^3.5.0",
"bluebird": "^3.5.2",
"debug": "^3.1.0",
"is-valid-domain": "0.0.5",
"ping": "^0.2.2",
"request": "^2.83.0"
"request": "^2.88.0"
},
"devDependencies": {
"chai": "^4.1.2",
"coveralls": "^3.0.0",
"coveralls": "^3.0.2",
"istanbul": "^0.4.5",
"mocha": "^3.5.3"
},
Expand Down
51 changes: 51 additions & 0 deletions test.js
@@ -0,0 +1,51 @@

const request = require('request');

let urls = [
{ url: 'https://sellstar.pt', start: 0, duration: 0 },
{ url: 'https://formafit.pt', start: 0, duration: 0 },
{ url: 'https://formafit.it', start: 0, duration: 0 },
{ url: 'https://formafit.es', start: 0, duration: 0 },
{ url: 'https://formafit.co.uk', start: 0, duration: 0 },
{ url: 'https://formafitness.fr', start: 0, duration: 0 },
{ url: 'https://formafitness.de', start: 0, duration: 0 },
{ url: 'https://formafitness.be', start: 0, duration: 0 },
{ url: 'https://giftlandia.eu', start: 0, duration: 0 },
{ url: 'https://sexo-saudavel.com', start: 0, duration: 0 },
{ url: 'http://comparaepoupa.pt', start: 0, duration: 0 },
{ url: 'http://talent.pt', start: 0, duration: 0 },
{ url: 'http://www.inosat.pt', start: 0, duration: 0 },
{ url: 'https://imoveis.profitignition.pt', start: 0, duration: 0 },
];

function pingUrls() {
if (urls.length > 0) {
let url = urls.shift();
process.stdout.write(url.url);
url.start = new Date();
request(url.url, (error, response, body) => {
url.duration = new Date() - url.start;
if (error) {
console.error(' | error | ', error.message, ' | ', url.duration);
} else {
console.log(' | done | ', response.statusCode, ' | ', url.duration);
}
pingUrls();
});
}
}

pingUrls();

// urls.forEach(url => {
// console.log('url:', url.url);
// url.start = new Date();
// request(url.url, (error, response, body) => {
// url.duration = new Date() - url.start;
// if (error) {
// console.error('error:', url.url, error, url.duration);
// } else {
// console.log('done:', url.url, response.statusCode, url.duration);
// }
// });
// });
63 changes: 63 additions & 0 deletions test2.js
@@ -0,0 +1,63 @@
const cluster = require('cluster');
const numCPUs = require('os').cpus().length;
// const dp = require('./domain-ping');
const request = require('request');

let urls = [
{ url: 'https://sellstar.pt', start: 0, duration: 0 },
// { url: 'https://formafit.pt', start: 0, duration: 0 },
// { url: 'https://formafit.it', start: 0, duration: 0 },
// { url: 'https://formafit.es', start: 0, duration: 0 },
// { url: 'https://formafit.co.uk', start: 0, duration: 0 },
// { url: 'https://formafitness.fr', start: 0, duration: 0 },
// { url: 'https://formafitness.de', start: 0, duration: 0 },
// { url: 'https://formafitness.be', start: 0, duration: 0 },
// { url: 'https://giftlandia.eu', start: 0, duration: 0 },
// { url: 'https://sexo-saudavel.com', start: 0, duration: 0 },
// { url: 'http://comparaepoupa.pt', start: 0, duration: 0 },
// { url: 'http://talent.pt', start: 0, duration: 0 },
// { url: 'http://www.inosat.pt', start: 0, duration: 0 },
// { url: 'https://imoveis.profitignition.pt', start: 0, duration: 0 }
];

function pingUrls(worker) {
if (urls.length > 0) {
let url = urls.shift();
// process.stdout.write(url.url);
url.start = new Date();
request(url.url, (error, response, body) => {
url.duration = new Date() - url.start;
if (error) {
console.error(url.url, ' | error | ', error.message, ' | ', url.duration);
} else {
console.log(url.url, ' | done | ', response.statusCode, ' | ', url.duration);
}
pingUrls();
});
}
}



if (cluster.isMaster) {
// Fork workers.
for (var i = 0; i < numCPUs; i++) {
console.log('launching cpu', i);
cluster.fork();
}

cluster.on('exit', (worker, code, signal) => {
console.log(`worker ${worker.process.pid} died`);
});
} else {
console.log('pinging');
pingUrls();
process.exit();
// dp('sellstar.pt').then(console.log).catch(console.error);
}



// const dp = require('./domain-ping');

// dp('sapo.pt').then(console.log).catch(console.error);

0 comments on commit bf581fb

Please sign in to comment.