"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RemoveDanglingResumableUploadsScheduler = void 0;
const tslib_1 = require("tslib");
const logger_1 = require("../../helpers/logger");
const constants_1 = require("../../initializers/constants");
const uploadx_1 = require("../uploadx");
const abstract_scheduler_1 = require("./abstract-scheduler");
const lTags = (0, logger_1.loggerTagsFactory)('scheduler', 'resumable-upload', 'cleaner');
class RemoveDanglingResumableUploadsScheduler extends abstract_scheduler_1.AbstractScheduler {
    constructor() {
        super();
        this.schedulerIntervalMs = constants_1.SCHEDULER_INTERVALS_MS.REMOVE_DANGLING_RESUMABLE_UPLOADS;
        this.lastExecutionTimeMs = new Date().getTime();
    }
    internalExecute() {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            logger_1.logger.debug('Removing dangling resumable uploads', lTags());
            const now = new Date().getTime();
            try {
                yield uploadx_1.uploadx.storage.purge(now - this.lastExecutionTimeMs);
            }
            catch (error) {
                logger_1.logger.error('Failed to handle file during resumable video upload folder cleanup', Object.assign({ error }, lTags()));
            }
            finally {
                this.lastExecutionTimeMs = now;
            }
        });
    }
    static get Instance() {
        return this.instance || (this.instance = new this());
    }
}
exports.RemoveDanglingResumableUploadsScheduler = RemoveDanglingResumableUploadsScheduler;
//# sourceMappingURL=remove-dangling-resumable-uploads-scheduler.js.map