-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstart.js
109 lines (88 loc) · 3.36 KB
/
start.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Built-in modules
// 3rd-party dependencies
const { DateTime } = require('luxon')
// In-house modules
const { config } = require('./config.js')
const {
compressAllLogsToArchive,
compressLogToArchive,
saveSessionLogHuman,
saveSessionLogJSON,
readJSONLogIntoSession
} = require('./logging.js')
const { Pinguno } = require('./pinguno.js')
const { Stats } = require('./stats.js')
if (config.nodeVerbose >= 2){
console.info(' -----\nStarting Pinguno\n -----') // verbose 2
console.info(`Process PID: ${process.pid}`) // verbose 2
console.info(`process.cwd: ${process.cwd()}`) // verbose 2
console.info(`process.execPath: ${process.execPath}`) // verbose 2
}
let app = new Pinguno()
if (config.nodeVerbose >= 2){
app.tellStatus()
}
app.startPinging(
app.pingTargets
/*, app.pingEngineEnum.NodeNetPing*/
)
let connectionStatusTick = setInterval(()=>{
app.updateInternetConnectionStatus()
console.log(DateTime.local().toFormat('yyyy-LL-dd HH:mm:ss.SSS') + ' Internet connected?: ' + app.updateInternetConnectionStatus().humanName)
}, app.opt.connectionStatusIntervalMs)
let updateOutagesTick = setInterval(()=>{
app.updateOutages()
}, app.opt.updateOutagesIntervalMs)
let writeToFileTick = setInterval(()=>{
Promise.resolve(saveSessionLogJSON(app)).then((val)=>{
// TEMP
// Testing reading from file into a new Pinguno session
/*console.debug('WriteToFile outcome:', val)
if (typeof val === 'string'){
readJSONLogIntoSession(app.activeLogUri).then((newSessionFromRead)=>{
console.debug('readJSONLogIntoSession - newSessionFromRead:', !!newSessionFromRead)
},(err)=>{
console.debug('readJSONLogIntoSession - error:', err)
})
}*/
}, (err)=>{
console.error(err)
})
}, app.opt.writeToFileIntervalMs)
// let mockSession = readJSONLogIntoSession('./dev-materials/test-data_frequent-disconnects.json')
let exportSessionToTextSummaryTick = setInterval(()=>{
saveSessionLogHuman(app)
}, app.opt.exportSessionToTextSummaryIntervalMs)
let updateSessionEndTimeTick = setInterval(()=>{
app.updateSessionEndTime()
}, app.opt.updateSessionEndTimeIntervalMs)
let statsTick = setInterval(()=>{
app.updateSessionStats()
console.info(app.sessionStats)
}, app.opt.updateSessionStatsIntervalMs)
// Periodically compress all loose JSON logs to a single gzipped archive
// let compressLogToArchiveTick = setInterval(()=>{
// compressLogToArchive(MyUtil.filenameFromUri(app.activeLogUri), app.opt.archiveDir, app.opt.logsDir)
// }, 20 * 1000)
// let compressAllLogsToArchiveTick = setInterval(()=>{
// compressAllLogsToArchive(app.opt.logsDir, app.opt.archiveDir, app.opt.logStandardFilename, app.opt.compressAnyJsonLogs)
// }, 5 * 1000)
// TEMP: USING PRE-COOKED DATA
// let updateOutagesTick = setInterval(()=>{
// app.readCombinedListFromFile('./logs/test-data_frequent-disconnects.json', (fileData)=>{
// app.updateOutages(fileData.combinedPingList, fileData.targetList)
// })
// }, 2 * 1000)
let handlePOSIXSignal = (signalStr)=>{
if (signalStr === 'SIGINT'){
console.info('\nReceived SIGINT; program is now exiting. If it takes too long, press Control-\\ to force exit.')
process.exit()
}
// Regardless of specific signal, ensure we exit
process.exit()
}
process.on('SIGINT', handlePOSIXSignal)
process.on('exit', (code)=>{
// Everything returned asynchronously will be ignored before the program exits
console.info(`start.js - About to exit with code: ${code}`)
})