@grouparoo/core
Version:
The Grouparoo Core
66 lines (65 loc) • 2.79 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DestroySweeper = void 0;
const clsTask_1 = require("../../classes/tasks/clsTask");
const Property_1 = require("../../models/Property");
const cls_1 = require("../../modules/cls");
const Source_1 = require("../../models/Source");
const App_1 = require("../../models/App");
const Destination_1 = require("../../models/Destination");
const Group_1 = require("../../models/Group");
const record_1 = require("../../modules/ops/record");
const GrouparooModel_1 = require("../../models/GrouparooModel");
class DestroySweeper extends clsTask_1.CLSTask {
constructor() {
super(...arguments);
this.name = "destroy";
this.description = "enqueue destroy tasks for models waiting to be deleted";
this.frequency = 1000 * 30;
this.queue = "system";
}
async runWithinTransaction() {
// -- GROUPS --
const groups = await Group_1.Group.findAll({ where: { state: "deleted" } });
for (const group of groups) {
await cls_1.CLS.enqueueTask("group:destroy", { groupId: group.id });
}
// --- DESTINATIONS --
const destinations = await Destination_1.Destination.findAll({
where: { state: "deleted" },
});
for (const destination of destinations) {
await cls_1.CLS.enqueueTask("destination:destroy", {
destinationId: destination.id,
});
}
// --- PROPERTIES ---
const properties = await Property_1.Property.findAll({ where: { state: "deleted" } });
for (const property of properties) {
await cls_1.CLS.enqueueTask("property:destroy", { propertyId: property.id });
}
// --- SOURCES ---
const sources = await Source_1.Source.findAll({ where: { state: "deleted" } });
for (const source of sources) {
await cls_1.CLS.enqueueTask("source:destroy", { sourceId: source.id });
}
// --- MODELS ---
const models = await GrouparooModel_1.GrouparooModel.findAll({
where: { state: "deleted" },
});
for (const model of models) {
await cls_1.CLS.enqueueTask("model:destroy", { modelId: model.id });
}
// --- APPS ---
const apps = await App_1.App.findAll({ where: { state: "deleted" } });
for (const app of apps) {
await cls_1.CLS.enqueueTask("app:destroy", { appId: app.id });
}
// --- RECORDS ---
const records = await record_1.RecordOps.getRecordsToDestroy();
for (const record of records) {
await cls_1.CLS.enqueueTask("record:destroy", { recordId: record.id });
}
}
}
exports.DestroySweeper = DestroySweeper;