Updated dependencies. Added periodic memory logger.
This commit is contained in:
59
src/app.js
59
src/app.js
@@ -22,6 +22,7 @@ const { flushOrphanedMedia } = require('./media');
|
||||
const getFileEntries = require('./utils/file-entries');
|
||||
|
||||
const inspector = new Inspector();
|
||||
let done = false;
|
||||
|
||||
function logActive() {
|
||||
console.log('log active!');
|
||||
@@ -32,24 +33,47 @@ function logActive() {
|
||||
}, typeof argv.logActive === 'number' ? argv.logActive : 60000);
|
||||
}
|
||||
|
||||
/*
|
||||
function monitorMemory() {
|
||||
logger.debug(`Memory usage: ${process.memoryUsage.rss() / 1000000} MB`);
|
||||
|
||||
if (!done) {
|
||||
setTimeout(() => monitorMemory(), 10000);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
async function stopMemorySample() {
|
||||
const profile = await inspector.heap.stopSampling();
|
||||
const filepath = `${dayjs().format('YYYY-MM-DD_HH-mm-ss')}.heapprofile`;
|
||||
|
||||
await inspector.heap.disable();
|
||||
|
||||
fs.writeFile(filepath, JSON.stringify(profile));
|
||||
await fs.writeFile(filepath, JSON.stringify(profile));
|
||||
|
||||
logger.info(`Saved heap sample to ${filepath}`);
|
||||
}
|
||||
|
||||
async function startMemorySample() {
|
||||
await inspector.heap.enable();
|
||||
await inspector.heap.startSampling();
|
||||
|
||||
// monitorMemory();
|
||||
|
||||
logger.info(`Start heap sampling, memory usage: ${process.memoryUsage.rss() / 1000000} MB`);
|
||||
|
||||
setTimeout(async () => {
|
||||
await stopMemorySample();
|
||||
|
||||
if (!done) {
|
||||
await startMemorySample();
|
||||
}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
async function init() {
|
||||
try {
|
||||
if (argv.memory) {
|
||||
await inspector.heap.enable();
|
||||
await inspector.heap.startSampling();
|
||||
|
||||
logger.info('Started heap sampling');
|
||||
await startMemorySample();
|
||||
}
|
||||
|
||||
if (argv.logActive) {
|
||||
@@ -122,7 +146,7 @@ async function init() {
|
||||
const actorNames = (argv.actors || []).concat(actorsFromFile || []);
|
||||
|
||||
const actors = (argv.actors || argv.actorsUpdate || argv.actorsFile) && await scrapeActors(actorNames);
|
||||
const actorBaseScenes = argv.actors && argv.actorScenes && actors.map(actor => actor.scenes).flat().filter(Boolean);
|
||||
const actorBaseScenes = argv.actors && argv.actorScenes && actors.map((actor) => actor.scenes).flat().filter(Boolean);
|
||||
|
||||
const updateBaseScenes = (argv.latest || argv.upcoming || argv.channels || argv.networks || argv.movies) && await fetchUpdates();
|
||||
|
||||
@@ -133,10 +157,10 @@ async function init() {
|
||||
? await fetchScenes([...(sceneUrls), ...(updateBaseScenes || []), ...(actorBaseScenes || [])])
|
||||
: [...(updateBaseScenes || []), ...(actorBaseScenes || [])];
|
||||
|
||||
const sceneMovies = deepScenes ? deepScenes.filter(scene => scene.movie).map(scene => ({ ...scene.movie, entity: scene.entity })) : [];
|
||||
const sceneMovies = deepScenes ? deepScenes.filter((scene) => scene.movie).map((scene) => ({ ...scene.movie, entity: scene.entity })) : [];
|
||||
const deepMovies = argv.sceneMovies || argv.movie ? await fetchMovies([...(argv.movie || []), ...(sceneMovies || [])]) : sceneMovies;
|
||||
|
||||
const movieScenes = argv.movieScenes ? deepMovies.map(movie => movie.scenes?.map(scene => ({ ...scene, movie, entity: movie.entity }))).flat().filter(Boolean) : [];
|
||||
const movieScenes = argv.movieScenes ? deepMovies.map((movie) => movie.scenes?.map((scene) => ({ ...scene, movie, entity: movie.entity }))).flat().filter(Boolean) : [];
|
||||
const deepMovieScenes = argv.deep ? await fetchScenes(movieScenes) : movieScenes;
|
||||
|
||||
if (argv.report) {
|
||||
@@ -150,23 +174,12 @@ async function init() {
|
||||
|
||||
await associateMovieScenes(storedMovies, storedScenes);
|
||||
}
|
||||
|
||||
if (argv.memory) {
|
||||
await stopMemorySample();
|
||||
}
|
||||
|
||||
knex.destroy();
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
|
||||
if (argv.memory) {
|
||||
await stopMemorySample();
|
||||
}
|
||||
|
||||
knex.destroy();
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
knex.destroy();
|
||||
done = true;
|
||||
}
|
||||
|
||||
module.exports = init;
|
||||
|
||||
Reference in New Issue
Block a user