Files
outline/server/queues/tasks/ErrorTimedOutImportsTask.ts
T
Tom MoorandClaude Opus 5.5 9e2565184e chore: Prune stale comments, TODOs, and type suppressions (#14092)
* chore: Remove unused lint disable directives

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH

* chore: Replace TODO type suppressions with typed code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH

* chore: Remove obsolete workaround comments in tests and MediaDimension

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH

* chore: Remove Tippy compatibility props from Tooltip

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH

* chore: Decouple DropdownMenu props from Tooltip and clarify sharing styles

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH

* chore: Remove stale retention TODOs from cleanup tasks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH

* chore: Register relations synchronously and clarify workaround comments

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH

* chore: Replace Notion import TODOs with descriptive comments

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-15 08:54:37 -04:00

93 lines
2.8 KiB
TypeScript

import { subHours } from "date-fns";
import { Op } from "sequelize";
import { ImportState, ImportTaskState } from "@shared/types";
import Logger from "@server/logging/Logger";
import { Import, ImportTask } from "@server/models";
import { sequelize } from "@server/storage/database";
import { TaskPriority } from "./base/BaseTask";
import type { Props } from "./base/CronTask";
import { CronTask, TaskInterval } from "./base/CronTask";
/**
* A task that moves the stuck imports to errored state.
*/
export default class ErrorTimedOutImportsTask extends CronTask {
public async perform({ limit }: Props) {
const thresholdHours = 24;
const cutOffTime = subHours(new Date(), thresholdHours);
const importsErrored: Record<string, boolean> = {};
try {
// oxlint-disable-next-line @typescript-eslint/no-explicit-any
await ImportTask.findAllInBatches<ImportTask<any>>(
{
where: {
state: [ImportTaskState.Created, ImportTaskState.InProgress],
createdAt: {
[Op.lt]: cutOffTime,
},
},
include: [
{
model: Import.unscoped(),
as: "import",
required: true,
},
],
order: [
["createdAt", "ASC"],
["id", "ASC"],
],
batchLimit: 1000,
totalLimit: limit,
},
async (importTasks) => {
for (const importTask of importTasks) {
const associatedImport = importTask.import;
if (associatedImport.state === ImportState.Canceled) {
continue; // import_tasks for a canceled import are not considered stuck.
}
await sequelize.transaction(async (transaction) => {
importTask.state = ImportTaskState.Errored;
importTask.error = "Timed out";
await importTask.save({ transaction });
// this import could have been seen before in another import_task.
if (!importsErrored[associatedImport.id]) {
associatedImport.state = ImportState.Errored;
associatedImport.error = "Timed out";
await associatedImport.save({ transaction });
importsErrored[associatedImport.id] = true;
}
});
}
}
);
} finally {
const totalImportsErrored = Object.keys(importsErrored).length;
if (totalImportsErrored > 0) {
Logger.info(
"task",
`Updated ${totalImportsErrored} imports to error status`
);
}
}
}
public get cron() {
return {
interval: TaskInterval.Hour,
};
}
public get options() {
return {
attempts: 1,
priority: TaskPriority.Background,
};
}
}