-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
79 lines (72 loc) · 2.07 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const yargs = require("yargs").argv;
var http = require("https");
const log4js = require("log4js");
require('dotenv').config()
log4js.configure({
appenders: {
out: {
type: 'stdout'
},
app: {
type: 'file',
filename: 'app.log'
},
queue: {
type: 'file',
filename: 'queue.log'
}
},
categories: {
default: {
appenders: ['app', 'out'],
level: 'all'
},
queue: {
appenders: ["queue", 'out'],
level: 'all'
}
}
});
const Queues = require("./utils/queue-manager");
const queues = new Queues();
const { performance, PerformanceObserver } = require("perf_hooks");
const obs = new PerformanceObserver((items) => {
let duration = items.getEntries()[0].duration;
console.log(`Program took ${duration / (1000 * 60)} minutes to complete`);
performance.clearMarks();
});
obs.observe({ entryTypes: ['measure'] });
async function main() {
performance.mark("A");
// implement this in queues whith number of max items set to max sockets in node try
// fetchProgramData();
let commands = yargs._;
let domains = yargs.domains.split(",");
if(!domains.length){
console.log("Domains required are empty");
return
}
if(commands.includes("query")){
domains.map((each) => {
queues.addJobToQueue("ctlogs",each);
})
} else {
console.log("Invalid Command");
return
}
}
process.on("exit", () => {
performance.mark("B");
performance.measure("A to B", "A", "B");
console.log("==================> EXIT <=================")
})
process.on("SIGINT", () => {
queues.emptyQueues();
performance.mark("B");
performance.measure("A to B", "A", "B");
console.log("==================> EXIT <=================")
})
main();
//function input as iterable vs every time invoking fucntion from main fucntion
//for loop block till asybnc code like primise await
// promise in fucntion return after resolve hope happnes check