Destroying knex when done to ensure process exit.

This commit is contained in:
2019-04-12 03:54:34 +02:00
parent a82fcf1e0a
commit d044aff9dd
5 changed files with 18 additions and 32 deletions

View File

@@ -1,6 +1,5 @@
'use strict';
const log = require('why-is-node-running');
const blessed = require('neo-blessed');
const clipboard = require('clipboardy');
@@ -44,24 +43,27 @@ function getMethod() {
async function init() {
const screen = argv.render && !argv.filename && initScreen();
try {
const method = getMethod();
const result = await method.fetch();
if (argv.copy && result.copy) {
clipboard.writeSync(result.copy);
console.log(`Result copied to clipboard: ${result.copy}`);
}
if (result) {
if (argv.copy && result.copy) {
clipboard.writeSync(result.copy);
console.log(`Result copied to clipboard: ${result.copy}`);
}
if (argv.filename && result.filename) {
console.log(result.filename);
if (argv.filename && result.filename) {
console.log(result.filename);
setTimeout(() => log(), 5000);
return;
}
// setTimeout(() => log(), 5000);
return;
}
if (argv.render) {
method.render(result, screen);
if (argv.render) {
method.render(result, screen);
}
}
} catch (error) {
console.error(argv.debug ? error : error.message);

View File

@@ -176,6 +176,8 @@ async function fetchReleases() {
return [];
}));
knex.destroy();
const accumulatedScenes = scenesPerSite.reduce((acc, siteScenes) => ([...acc, ...siteScenes]), []);
const sortedScenes = accumulatedScenes.sort(({ date: dateA }, { date: dateB }) => moment(dateB).diff(dateA));

View File

@@ -87,6 +87,8 @@ async function fetchScene(url) {
const scene = await scraper.fetchScene(url, site);
const filename = deriveFilename(scene);
knex.destroy();
return {
...scene,
filename,