mirror of
https://github.com/outline/outline.git
synced 2026-01-07 19:49:58 -06:00
* wip * Implementation complete * tidying * test * Address feedback * Remove duplicative retry logic from UpdateDocumentsPopularityScoreTask. Now that we're split across many runs this is not neccessary * Refactor to subclass, config to instance * Refactor BaseTask to named export * fix: Missing partition * tsc * Feedback
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { subHours } from "date-fns";
|
|
import { Op } from "sequelize";
|
|
import { FileOperationState } from "@shared/types";
|
|
import Logger from "@server/logging/Logger";
|
|
import { FileOperation } from "@server/models";
|
|
import { TaskPriority } from "./base/BaseTask";
|
|
import { CronTask, TaskInterval, Props } from "./base/CronTask";
|
|
|
|
export default class ErrorTimedOutFileOperationsTask extends CronTask {
|
|
public async perform({ limit }: Props) {
|
|
Logger.info("task", `Error file operations running longer than 12 hours…`);
|
|
const fileOperations = await FileOperation.unscoped().findAll({
|
|
where: {
|
|
createdAt: {
|
|
[Op.lt]: subHours(new Date(), 12),
|
|
},
|
|
[Op.or]: [
|
|
{
|
|
state: FileOperationState.Creating,
|
|
},
|
|
{
|
|
state: FileOperationState.Uploading,
|
|
},
|
|
],
|
|
},
|
|
limit,
|
|
});
|
|
await Promise.all(
|
|
fileOperations.map(async (fileOperation) => {
|
|
fileOperation.state = FileOperationState.Error;
|
|
fileOperation.error = "Timed out";
|
|
await fileOperation.save({ hooks: false });
|
|
})
|
|
);
|
|
Logger.info("task", `Updated ${fileOperations.length} file operations`);
|
|
}
|
|
|
|
public get cron() {
|
|
return {
|
|
interval: TaskInterval.Hour,
|
|
};
|
|
}
|
|
|
|
public get options() {
|
|
return {
|
|
attempts: 1,
|
|
priority: TaskPriority.Background,
|
|
};
|
|
}
|
|
}
|