fix: misc bug fixes and reliability improvements

- Fix `refreshCreditsJob` to treat `null` `lastFetchedAt` as needing refresh (not just missing cast entry)
- Fix `buildBackupCron` 6h expression to correctly fire every 6 hours using explicit hour list instead of `*/6`
- Fix `vacuumDatabase` to pass the path directly as a bound parameter (the manual escape was redundant and incorrect)
- Clean up orphaned `.tmp` files when image cache writes fail in both `downloadAndCacheImage` and `fetchAndMaybeCache`
- Surface import job payload parse/validation errors as job-level `error` status instead of throwing unhandled exceptions; check for cancellation before the processing loop starts
- Replace bare `Error` throws in `readImportJob` with `ORPCError` (`NOT_FOUND` / `FORBIDDEN`) so oRPC maps them to correct HTTP status codes
- Auto-promote title status to `in_progress` when `logEpisodeWatchBatch` is called for titles that have no status or are only on the watchlist
- Refresh seasons from TMDB when a webhook references a season not yet in the DB (handles newly-released seasons)
- Upgrade fire-and-forget enrichment failures and webhook processing errors from `log.debug` → `log.warn` so they surface in production logs
This commit is contained in:
2026-03-22 10:57:48 -04:00
parent 72f26f822c
commit 3f05e08fea
10 changed files with 84 additions and 21 deletions
+2 -2
View File
@@ -171,7 +171,7 @@ export const createJob = os.imports.createJob.use(authed).handler(async ({ input
log.error(`Import job ${job.id} failed:`, err);
});
return readImportJob(job.id);
return readImportJob(job.id, context.user.id);
});
export const getJob = os.imports.getJob.use(authed).handler(({ input, context }) => {
@@ -187,7 +187,7 @@ export const cancelJob = os.imports.cancelJob.use(authed).handler(({ input, cont
});
}
updateImportJobProgress(input.id, { status: "cancelled" });
return readImportJob(input.id);
return readImportJob(input.id, context.user.id);
});
export const jobEvents = os.imports.jobEvents.use(authed).handler(async function* ({
+6 -1
View File
@@ -13,10 +13,13 @@ import {
removeTitleStatus,
setTitleStatus,
} from "@sofa/core/tracking";
import { createLogger } from "@sofa/logger";
import { os } from "../context";
import { authed } from "../middleware";
const log = createLogger("titles");
export const detail = os.titles.detail.use(authed).handler(async ({ input }) => {
const result = await getOrFetchTitle(input.id);
if (!result)
@@ -77,7 +80,9 @@ export const quickAdd = os.titles.quickAdd.use(authed).handler(async ({ input, c
}
// Trigger full TMDB import if still a shell (fire-and-forget)
getOrFetchTitleByTmdbId(result.tmdbId, result.type as "movie" | "tv").catch(() => {});
getOrFetchTitleByTmdbId(result.tmdbId, result.type as "movie" | "tv").catch((err) => {
log.warn(`Failed to import ${result.type} TMDB ${result.tmdbId}:`, err);
});
return { id: result.id, alreadyAdded: result.alreadyAdded };
});