This commit is contained in:
parent
becd2e6f48
commit
8e976d2e4f
|
@ -325,6 +325,4 @@ INSERT INTO mysql.roles_mapping (`User`, `Host`, `Role`, `Admin_option`)
|
|||
WHERE `User` LIKE @prefixedLike AND `Host` = @genRoleHost;
|
||||
|
||||
|
||||
TRUNCATE util.vn_schedules;
|
||||
|
||||
FLUSH PRIVILEGES;
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `VN_SCHEDULER`
|
||||
ON SCHEDULE EVERY 1 DAY
|
||||
STARTS CURRENT_TIMESTAMP + INTERVAL 1 DAY
|
||||
ENABLE
|
||||
DO BEGIN
|
||||
/**
|
||||
* Ejecuta el PROCEDURE que comprueba si hay procedimientos planificados para ejecutar
|
||||
*
|
||||
*/
|
||||
CALL `VN_SCHEDULER`();
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
|
@ -1,67 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`VN_SCHEDULER`()
|
||||
BEGIN
|
||||
/**
|
||||
* Ejecuta los procedimientos que se han programado a demanda.
|
||||
*
|
||||
*/
|
||||
DECLARE vDone BOOL;
|
||||
DECLARE vError VARCHAR(255) DEFAULT NULL;
|
||||
DECLARE vErrorCode VARCHAR(255) DEFAULT NULL;
|
||||
DECLARE vSchema VARCHAR(255);
|
||||
DECLARE vStatus VARCHAR(255);
|
||||
DECLARE vProcedure VARCHAR(255);
|
||||
|
||||
DECLARE vScheduleFk INT;
|
||||
-- Obtener datos de la tabla vn_schedules
|
||||
DECLARE vQueue CURSOR FOR
|
||||
SELECT id, `schema`, `procedure`, `status`
|
||||
FROM vn_schedules
|
||||
WHERE status = 'scheduled';
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||
GET DIAGNOSTICS CONDITION 1
|
||||
vError = MESSAGE_TEXT,
|
||||
vErrorCode = RETURNED_SQLSTATE;
|
||||
OPEN vQueue;
|
||||
l: LOOP
|
||||
SET vDone = FALSE;
|
||||
FETCH vQueue INTO vScheduleFk, vSchema, vProcedure, vStatus;
|
||||
|
||||
IF vDone THEN
|
||||
LEAVE l;
|
||||
END IF;
|
||||
|
||||
UPDATE vn_schedules
|
||||
SET `started` = util.VN_NOW(),
|
||||
`finished` = NULL,
|
||||
`error` = NULL,
|
||||
`errorCode` = NULL
|
||||
WHERE id = vScheduleFk;
|
||||
|
||||
SET vError = NULL;
|
||||
|
||||
|
||||
CALL util.exec(CONCAT('CALL `', vSchema ,'`.`', vProcedure ,'`'));
|
||||
|
||||
IF vError IS NOT NULL THEN
|
||||
UPDATE vn_schedules
|
||||
SET `error` = vError,
|
||||
finished = util.VN_NOW(),
|
||||
lastFinished = util.VN_NOW(),
|
||||
`errorCode` = vErrorCode,
|
||||
`status` = 'error'
|
||||
WHERE id = vScheduleFk;
|
||||
ELSE
|
||||
UPDATE vn_schedules
|
||||
SET `error` = vError,
|
||||
`errorCode` = vErrorCode,
|
||||
finished = util.VN_NOW(),
|
||||
lastFinished = util.VN_NOW(),
|
||||
`status` = 'exec'
|
||||
WHERE id = vScheduleFk;
|
||||
END IF;
|
||||
END LOOP;
|
||||
CLOSE vQueue;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
|
@ -9,11 +9,6 @@ BEGIN
|
|||
`changedModelId` = OLD.zoneFk,
|
||||
`userFk` = account.myUser_getId();
|
||||
|
||||
-- Inserta en vn_schedules para ejecutar el procedure de 'zone_getCollisions'
|
||||
|
||||
INSERT IGNORE INTO `util`.`vn_schedules`(`schema`, `procedure`)
|
||||
VALUES
|
||||
('vn', 'zone_getCollisions');
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -5,11 +5,5 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneIncluded_beforeIn
|
|||
BEGIN
|
||||
SET NEW.editorFk = account.myUser_getId();
|
||||
|
||||
-- Inserta en vn_schedules para ejecutar el procedure de 'zone_getCollisions'
|
||||
|
||||
INSERT IGNORE INTO `util`.`vn_schedules`(`schema`, `procedure`)
|
||||
VALUES
|
||||
('vn', 'zone_getCollisions');
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -4,11 +4,5 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneIncluded_beforeUp
|
|||
FOR EACH ROW
|
||||
BEGIN
|
||||
SET NEW.editorFk = account.myUser_getId();
|
||||
|
||||
-- Inserta en vn_schedules para ejecutar el procedure de 'zone_getCollisions'
|
||||
|
||||
INSERT IGNORE INTO `util`.`vn_schedules`(`schema`, `procedure`)
|
||||
VALUES
|
||||
('vn', 'zone_getCollisions');
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
CREATE TABLE IF NOT EXISTS `util`.`vn_schedules` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`started` datetime DEFAULT NULL,
|
||||
`finished` datetime DEFAULT NULL,
|
||||
`lastFinished` datetime DEFAULT NULL,
|
||||
`order` int(11) DEFAULT NULL,
|
||||
`schema` varchar(45) NOT NULL,
|
||||
`procedure` varchar(100) NOT NULL,
|
||||
`error` varchar(255) DEFAULT NULL,
|
||||
`errorCode` varchar(10) DEFAULT NULL,
|
||||
`status` enum('scheduled','exec','error') NOT NULL DEFAULT 'scheduled',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY unique_schedule (`schema`, `procedure`, `status`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
|
@ -20,12 +20,10 @@ describe('zone toggleIsIncluded()', () => {
|
|||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
await validateSchedules('before', options);
|
||||
|
||||
let result = await models.Zone.toggleIsIncluded(1, 20, true, options);
|
||||
|
||||
expect(result.isIncluded).toBeTrue();
|
||||
await validateSchedules('after', options);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
|
@ -39,12 +37,10 @@ describe('zone toggleIsIncluded()', () => {
|
|||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
await validateSchedules('before', options);
|
||||
|
||||
let result = await models.Zone.toggleIsIncluded(1, 20, false, options);
|
||||
|
||||
expect(result.isIncluded).toBeFalse();
|
||||
await validateSchedules('after', options);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
|
@ -58,14 +54,13 @@ describe('zone toggleIsIncluded()', () => {
|
|||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
await validateSchedules('before', options);
|
||||
|
||||
await models.Zone.toggleIsIncluded(1, 20, false, options);
|
||||
|
||||
const result = await models.Zone.toggleIsIncluded(1, 20, undefined, options);
|
||||
|
||||
expect(result).toEqual({count: 1});
|
||||
|
||||
await validateSchedules('after', options);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
|
@ -73,22 +68,3 @@ describe('zone toggleIsIncluded()', () => {
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
async function validateSchedules(step, options = null) {
|
||||
const querySchedules = `SELECT count(*) count FROM util.vn_schedules;`;
|
||||
|
||||
switch (step) {
|
||||
case 'before': {
|
||||
const [{count}] = await models.Application.rawSql(querySchedules, null, options);
|
||||
|
||||
expect(count).toEqual(0);
|
||||
}
|
||||
break;
|
||||
case 'after': {
|
||||
const [{count}] = await models.Application.rawSql(querySchedules, null, options);
|
||||
|
||||
expect(count).toEqual(1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue