Created
October 30, 2017 16:04
-
-
Save crizstian/05f76fb85bc4fea7a3ecf4a19a5a6293 to your computer and use it in GitHub Desktop.
workers logic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ############################################## | |
// WORKERS | |
} else if (process.env.WorkerName === 'readlogs') { | |
console.log('ππ½ Worker readlogs ' + process.pid + ' has started.') | |
process.on('message', async ({logfiles}) => { | |
try { | |
const read = await readLogFiles.parseFiles(logfiles) | |
process.send({read, logfiles}) | |
} catch (e) { | |
console.log(`something went wrong with reading logs => ${e}`) | |
process.exit(0) | |
} | |
}) | |
} else if (process.env.WorkerName === 'savelogs') { | |
console.log('ππ½ Worker savelogs ' + process.pid + ' has started.') | |
process.on('message', async ({read, collection}) => { | |
try { | |
const save = await saveToDB.saveToDB(read, collection) | |
console.log(`RECORDS SAVED IN ${collection} => ${save.reduce((prev, cur) => prev + cur, 0)} π€`) | |
} catch (e) { | |
console.log(`something went wrong with saving parsed logs => ${e}`) | |
process.exit(0) | |
} | |
}) | |
} else if (process.env.WorkerName === 'deletelogs') { | |
console.log('ππ½ Worker deletelogs ' + process.pid + ' has started. ') | |
process.on('message', async ({logfiles, type}) => { | |
try { | |
const deleted = await moveAndDelete.deleteFiles(logfiles) | |
console.log(`LOCAL LOGS DELETED => ${deleted.length}`) | |
} catch (e) { | |
console.log(`something went wrong with deleting local logs => ${e}`) | |
process.exit(0) | |
} | |
}) | |
} else if (process.env.WorkerName === 'movelogs') { | |
console.log('ππ½ Worker movelogs ' + process.pid + ' has started.') | |
process.on('message', async ({logfiles}) => { | |
try { | |
moveAndDelete.renameFiles(logfiles) | |
.then(async moved => console.log(`REMOTE LOGS MOVED =>`, await moved.length)) | |
} catch (e) { | |
console.log(`something went wrong with moving remote logs => ${e}`) | |
process.exit(0) | |
} | |
}) | |
} else if (process.env.WorkerName === 'geolocation') { | |
console.log('ππ½ Worker geolocation ' + process.pid + ' has started.') | |
process.on('message', async (read) => { | |
try { | |
geoip.getLocations(read) | |
.then(async locations => process.send(locations)) | |
} catch (e) { | |
console.log(`something went wrong locating ips => ${e}`) | |
process.exit(0) | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment