mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
42959d66db
* 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
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import { subDays } 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, Props, TaskInterval } from "./base/CronTask";
|
|
|
|
export default class CleanupExpiredFileOperationsTask extends CronTask {
|
|
public async perform({ limit }: Props) {
|
|
Logger.info("task", `Expiring file operations older than 15 days…`);
|
|
const fileOperations = await FileOperation.unscoped().findAll({
|
|
where: {
|
|
createdAt: {
|
|
[Op.lt]: subDays(new Date(), 15),
|
|
},
|
|
state: {
|
|
[Op.ne]: FileOperationState.Expired,
|
|
},
|
|
},
|
|
limit,
|
|
});
|
|
await Promise.all(
|
|
fileOperations.map((fileOperation) => fileOperation.expire())
|
|
);
|
|
Logger.info("task", `Expired ${fileOperations.length} file operations`);
|
|
}
|
|
|
|
public get cron() {
|
|
return {
|
|
interval: TaskInterval.Hour,
|
|
};
|
|
}
|
|
|
|
public get options() {
|
|
return {
|
|
attempts: 1,
|
|
priority: TaskPriority.Background,
|
|
};
|
|
}
|
|
}
|