Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions ingest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,14 @@ export async function updateDb(
const mailPaths = getLoginMails(prefix);

const doUpdate = async () => {
const res = await updatePaths(bookPaths, collectionPaths, resourcePaths, mailPaths, db, buildId, prevBuild, prefix, moved, relaxed);
let res: number | boolean = false;
try {
res = await updatePaths(bookPaths, collectionPaths, resourcePaths, mailPaths, db, buildId, prevBuild, prefix, moved, relaxed);
} catch (e) {
console.error(`Error updating ${prefix}:`, e);
await db.exec("ROLLBACK").catch(() => {});
return false;
}
if (res !== false) {
prevBuild = new Date();
}
Expand All @@ -119,8 +126,7 @@ export async function updateDb(
return res !== false;
}

anyErrors = anyErrors || !
await doUpdate();
anyErrors = anyErrors || !await doUpdate();

if (dev) {
getDevWebSocketServer();
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"slugify": "^1.6.6",
"sqlite": "^5.1.1",
"sqlite3": "^5.1.7",
"tree-kill": "^1.2.2",
"unified": "^11.0.5",
"unist-util-visit": "^5.0.0",
"uuid": "^14.0.0",
Expand Down
15 changes: 10 additions & 5 deletions scripts/ingest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ dotenv.config({ path: ".env.local" });

import { program } from "commander";
import readline from "readline";
import fs from "fs";
import kill from "tree-kill";

import { updateDb } from "@/ingest";
import { rebuildDatabase } from "@/ingest/createDb";
Expand All @@ -17,6 +17,7 @@ const startNext = () => {
{
stdio: "inherit",
shell: true,
detached: true,
env: process.env
}
);
Expand Down Expand Up @@ -80,10 +81,14 @@ const ask = (question: string): Promise<string> => {

if (dev) {
const nextProcess = startNext();
const shutdown = () => {
nextProcess.kill("SIGTERM");
process.exit(0);
};
const shutdown = (reason?: unknown) => {
if (reason !== undefined) {
console.error("Error:", reason);
}
kill(nextProcess.pid!, "SIGTERM", () => process.exit());
Comment thread
janezd marked this conversation as resolved.
}
process.on("uncaughtException", shutdown);
process.on("unhandledRejection", shutdown);
process.on("SIGINT", shutdown);
process.on("SIGTERM", shutdown);
}
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6499,6 +6499,11 @@ toggle-selection@^1.0.6:
resolved "https://registry.yarnpkg.com/traverse/-/traverse-0.3.9.tgz#717b8f220cc0bb7b44e40514c22b2e8bbc70d8b9"
integrity sha512-iawgk0hLP3SxGKDfnDJf8wTz4p2qImnyihM5Hh/sGvQ3K37dPi/w8sRhdNIxYA1TwFwc5mDhIJq+O0RsvXBKdQ==

tree-kill@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.2.tgz#4ca09a9092c88b73a7cdc5e8a01b507b0790a0cc"
integrity sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==

trim-lines@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/trim-lines/-/trim-lines-3.0.1.tgz#d802e332a07df861c48802c04321017b1bd87338"
Expand Down
Loading