salix/modules/zone/back/models/zone-closure.js

27 lines
825 B
JavaScript
Raw Normal View History

2020-02-06 15:04:23 +00:00
const app = require('vn-loopback/server/server');
module.exports = Self => {
app.on('started', function() {
let models = ['Zone', 'ZoneEvent', 'ZoneExclusion'];
for (let modelName of models) {
let Model = app.models[modelName];
Model.observe('after save', doCalc);
Model.observe('after delete', doCalc);
}
async function doCalc(ctx) {
try {
2020-02-20 14:15:50 +00:00
await Self.rawSql(`
2023-11-21 08:26:02 +00:00
CREATE DEFINER = CURRENT_ROLE EVENT zoneClosure_doRecalc
2020-02-20 14:15:50 +00:00
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 15 SECOND
DO CALL zoneClosure_recalc;
`);
2020-02-06 15:04:23 +00:00
} catch (err) {
2020-02-20 14:15:50 +00:00
if (err.code != 'ER_EVENT_ALREADY_EXISTS') throw err;
2020-02-06 15:04:23 +00:00
}
}
});
};