Skip to content

Commit

Permalink
Added verbose options for the fresh/update handlers.
Browse files Browse the repository at this point in the history
Scripts now do some printing to show that something is actually happening.
  • Loading branch information
LTLA committed Feb 21, 2024
1 parent 4011a36 commit efcc23e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion scripts/fresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ const { list_projects, list_assets, list_versions, find_latest, read_summary, re
// just (re)aligning with whatever's in the bucket.
fs.writeFileSync(path.join(dir, "modified"), String((new Date).getTime()))

await freshHandler(db_paths, list_projects, list_assets, list_versions, find_latest, read_summary, read_metadata);
await freshHandler(db_paths, list_projects, list_assets, list_versions, find_latest, read_summary, read_metadata, { verbose: true });
2 changes: 1 addition & 1 deletion scripts/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const { list_logs, read_log, read_metadata, find_latest } = utils.chooseSourceFu

let lastmod_path = path.join(dir, "modified");
let lastmod = new Date(Number(fs.readFileSync(lastmod_path)));
let all_logs = await updateHandler(db_paths, lastmod, list_logs, read_log, read_metadata, find_latest);
let all_logs = await updateHandler(db_paths, lastmod, list_logs, read_log, read_metadata, find_latest, { verbose: true });

// Storing the timestamp of the last processed job.
if (all_logs.length) {
Expand Down
4 changes: 3 additions & 1 deletion src/handlers/freshHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { addVersion } from "../sqlite/addVersion.js";
import { createTables } from "../sqlite/createTables.js";
import Database from "better-sqlite3"

export async function freshHandler(db_paths, list_projects, list_assets, list_versions, find_latest, read_summary, read_metadata) {
export async function freshHandler(db_paths, list_projects, list_assets, list_versions, find_latest, read_summary, read_metadata, { verbose = false } = {}) {
const db_handles = {};
for (const [k, v] of Object.entries(db_paths)) {
if (fs.existsSync(v)) {
Expand All @@ -27,6 +27,8 @@ export async function freshHandler(db_paths, list_projects, list_assets, list_ve
if (outcome.status == "rejected") {
// Just report the error and keep going so that we don't stall at a single broken project.
console.error(new Error("failed to add project '" + all_projects[i] + "'", { cause: outcome.reason }));
} else if (verbose) {
console.log("added project '" + all_projects[i] + "'");
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/handlers/updateHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export async function readLogs(last_modified, list_logs, read_log) {
return logs;
}

export async function updateHandler(db_paths, last_modified, list_logs, read_log, read_metadata, find_latest) {
export async function updateHandler(db_paths, last_modified, list_logs, read_log, read_metadata, find_latest, { verbose = false } = {}) {
const db_handles = {};
for (const [k, v] of Object.entries(db_paths)) {
db_handles[k] = Database(v);
Expand Down Expand Up @@ -142,6 +142,10 @@ export async function updateHandler(db_paths, last_modified, list_logs, read_log
} else {
throw new Error("unknown update action type '" + type + "'");
}

if (verbose) {
console.log("processed log '", l.name, "'");
}
} catch (err) {
// Report the error but keep going so that we don't stall at a single broken log.
console.error(new Error("failed update for '" + l.name + "' ('" + JSON.stringify(parameters) + "')", { cause: err }));
Expand Down

0 comments on commit efcc23e

Please sign in to comment.