UNPKG

@grouparoo/core

Version:
40 lines (39 loc) 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ModelDestroy = void 0; const clsTask_1 = require("../../classes/tasks/clsTask"); const GrouparooModel_1 = require("../../models/GrouparooModel"); class ModelDestroy extends clsTask_1.CLSTask { constructor() { super(...arguments); this.name = "model:destroy"; this.description = "wait for dependencies to finish being deleted, then delete the model"; this.frequency = 0; this.queue = "models"; this.inputs = { modelId: { required: true }, }; } async runWithinTransaction({ modelId }) { const model = await GrouparooModel_1.GrouparooModel.scope(null).findOne({ where: { id: modelId, state: "deleted" }, }); // the model may have been force-deleted if (!model) { return; } // check if we're still being used by something try { await GrouparooModel_1.GrouparooModel.ensureNotInUse(model); } catch (error) { if (error.message.match(/cannot delete this model,/)) { return; // check back later } throw error; } // all things that depend on this model have been cleaned up await model.destroy(); } } exports.ModelDestroy = ModelDestroy;