mirror of
https://github.com/zoriya/Kyoo.git
synced 2026-05-22 07:02:27 -04:00
api: logtape, otel, & logging improvements (#1230)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import path from "node:path";
|
||||
import { getCurrentSpan, setAttributes } from "@elysiajs/opentelemetry";
|
||||
import { getLogger } from "@logtape/logtape";
|
||||
import { SpanStatusCode } from "@opentelemetry/api";
|
||||
import { encode } from "blurhash";
|
||||
import { and, eq, is, lt, ne, type SQL, sql } from "drizzle-orm";
|
||||
@@ -14,6 +15,8 @@ import type { Image } from "~/models/utils";
|
||||
import { record } from "~/otel";
|
||||
import { getFile } from "~/utils";
|
||||
|
||||
const logger = getLogger();
|
||||
|
||||
export const imageDir = process.env.IMAGES_PATH ?? "/images";
|
||||
export const defaultBlurhash = "000000";
|
||||
|
||||
@@ -134,7 +137,16 @@ export const processImages = record(
|
||||
const client = (await db.$client.connect()) as PoolClient;
|
||||
client.on("notification", (evt) => {
|
||||
if (evt.channel !== "kyoo_image") return;
|
||||
processAll();
|
||||
try {
|
||||
processAll();
|
||||
} catch (e) {
|
||||
logger.error(
|
||||
"Failed to process images. Aborting images downloading. error={error}",
|
||||
{
|
||||
error: e,
|
||||
},
|
||||
);
|
||||
}
|
||||
});
|
||||
await client.query("listen kyoo_image");
|
||||
|
||||
@@ -193,14 +205,19 @@ const processOne = record("download", async () => {
|
||||
span.recordException(err);
|
||||
span.setStatus({ code: SpanStatusCode.ERROR });
|
||||
}
|
||||
console.error("Failed to download image", img.url, err);
|
||||
logger.error("Failed to download image. imageurl={url}, error={error}", {
|
||||
url: img.url,
|
||||
error: err,
|
||||
});
|
||||
try {
|
||||
await tx
|
||||
.update(images)
|
||||
.set({ attempt: sql`${images.attempt}+1` })
|
||||
.where(eq(images.pk, img.pk));
|
||||
} catch (e) {
|
||||
console.error("Failed to mark download as failed", e);
|
||||
logger.error("Failed to mark download as failed. error={error}", {
|
||||
error: e,
|
||||
});
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user