fix: File operation cleanup task should also remove import data
This commit is contained in:
@@ -11,11 +11,11 @@ import CleanupExpiredFileOperationsTask from "./CleanupExpiredFileOperationsTask
|
||||
beforeEach(() => flushdb());
|
||||
|
||||
describe("CleanupExpiredFileOperationsTask", () => {
|
||||
it("should expire exports older than 30 days ago", async () => {
|
||||
it("should expire exports older than 15 days ago", async () => {
|
||||
await buildFileOperation({
|
||||
type: FileOperationType.Export,
|
||||
state: FileOperationState.Complete,
|
||||
createdAt: subDays(new Date(), 30),
|
||||
createdAt: subDays(new Date(), 15),
|
||||
});
|
||||
await buildFileOperation({
|
||||
type: FileOperationType.Export,
|
||||
@@ -35,11 +35,11 @@ describe("CleanupExpiredFileOperationsTask", () => {
|
||||
expect(data).toEqual(1);
|
||||
});
|
||||
|
||||
it("should not expire exports made less than 30 days ago", async () => {
|
||||
it("should not expire exports made less than 15 days ago", async () => {
|
||||
await buildFileOperation({
|
||||
type: FileOperationType.Export,
|
||||
state: FileOperationState.Complete,
|
||||
createdAt: subDays(new Date(), 29),
|
||||
createdAt: subDays(new Date(), 14),
|
||||
});
|
||||
await buildFileOperation({
|
||||
type: FileOperationType.Export,
|
||||
|
||||
@@ -2,10 +2,7 @@ import { subDays } from "date-fns";
|
||||
import { Op } from "sequelize";
|
||||
import Logger from "@server/logging/Logger";
|
||||
import { FileOperation } from "@server/models";
|
||||
import {
|
||||
FileOperationState,
|
||||
FileOperationType,
|
||||
} from "@server/models/FileOperation";
|
||||
import { FileOperationState } from "@server/models/FileOperation";
|
||||
import BaseTask, { TaskPriority } from "./BaseTask";
|
||||
|
||||
type Props = {
|
||||
@@ -14,12 +11,11 @@ type Props = {
|
||||
|
||||
export default class CleanupExpiredFileOperationsTask extends BaseTask<Props> {
|
||||
public async perform({ limit }: Props) {
|
||||
Logger.info("task", `Expiring export file operations older than 30 days…`);
|
||||
Logger.info("task", `Expiring file operations older than 15 days…`);
|
||||
const fileOperations = await FileOperation.unscoped().findAll({
|
||||
where: {
|
||||
type: FileOperationType.Export,
|
||||
createdAt: {
|
||||
[Op.lt]: subDays(new Date(), 30),
|
||||
[Op.lt]: subDays(new Date(), 15),
|
||||
},
|
||||
state: {
|
||||
[Op.ne]: FileOperationState.Expired,
|
||||
|
||||
Reference in New Issue
Block a user