feat: Implement Telegram alerts for catalog updates and failures

This commit is contained in:
2026-10-20 23:14:32 +03:00
parent a95784df93
commit e28d65310d
10 changed files with 541 additions and 43 deletions

View File

@@ -154,13 +154,13 @@ async function build(catalog) {
try {
docs.push({ id: file.id, file, schedule: await scheduleFor(file) });
} catch (error) {
failed.push({ name: file.name, error: error.message });
failed.push({ id: file.id, name: file.name, error: error.message });
}
}
}),
);
index = {
catalogAt: catalog.updatedAt,
catalogVersion: versionOf(catalog),
year: catalog.year,
builtAt: new Date().toISOString(),
total: catalog.files.length,
@@ -171,16 +171,36 @@ async function build(catalog) {
return index;
}
/** The current index; rebuilt in the background when the catalog changes. */
export async function getIndex() {
const catalog = await getCatalog();
if ((!index || index.catalogAt !== catalog.updatedAt) && !building)
// A catalog's documents and their dates; older cached catalogs have only the time of the crawl.
const versionOf = (catalog) => catalog.version || catalog.updatedAt;
function rebuild(catalog) {
if (!building)
building = build(catalog).finally(() => {
building = null;
});
return building;
}
/**
* The current index; rebuilt in the background when a document of the catalog changes. A check
* that finds the catalog as it was keeps the index, so its ETags, and the clients' caches, hold.
*/
export async function getIndex() {
const catalog = await getCatalog();
if (!index || index.catalogVersion !== versionOf(catalog)) rebuild(catalog);
if (!index) await building;
return index;
}
/** The index of the catalog as it is now, waiting for the rebuild a change needs (the watcher). */
export async function syncIndex(catalog) {
if (!index || index.catalogVersion !== versionOf(catalog)) {
if (building) await building;
if (!index || index.catalogVersion !== versionOf(catalog)) await rebuild(catalog);
}
return index;
}
export const indexStatus = () =>
index
? {