feat: refs #6727 Added started and finished
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Guillermo Bonet 2024-07-19 08:27:39 +02:00
parent 4880d1497f
commit 930e2951b7
2 changed files with 29 additions and 14 deletions

View File

@ -13,7 +13,7 @@ BEGIN
DECLARE vQueue CURSOR FOR
SELECT schemaName, tableName, retentionDays
FROM logClean
FROM logCleanMultiConfig
ORDER BY `order`;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
@ -23,18 +23,31 @@ BEGIN
SET vDone = FALSE;
FETCH vQueue INTO vSchemaName, vTableName, vRetentionDays;
SET vSchemaName = util.quoteIdentifier(vSchemaName);
SET vTableName = util.quoteIdentifier(vTableName);
SET vDated = VN_CURDATE() - INTERVAL vRetentionDays DAY;
IF vRetentionDays THEN
IF vDone THEN
LEAVE l;
UPDATE logCleanMultiConfig
SET `started` = util.VN_NOW()
WHERE schemaName = vSchemaName
AND tableName = vTableName;
SET vSchemaName = util.quoteIdentifier(vSchemaName);
SET vTableName = util.quoteIdentifier(vTableName);
SET vDated = VN_CURDATE() - INTERVAL vRetentionDays DAY;
IF vDone THEN
LEAVE l;
END IF;
CALL util.exec(CONCAT(
'DELETE FROM ', vSchemaName , '.', vTableName,
" WHERE creationDate < '", vDated, "'"
));
UPDATE logCleanMultiConfig
SET `finished` = util.VN_NOW()
WHERE schemaName = vSchemaName
AND tableName = vTableName;
END IF;
CALL util.exec(CONCAT(
'DELETE FROM ', vSchemaName , '.', vTableName,
" WHERE creationDate < '", vDated, "'"
));
END LOOP;
CLOSE vQueue;
END$$

View File

@ -1,12 +1,14 @@
CREATE OR REPLACE TABLE `util`.`logClean` (
CREATE OR REPLACE TABLE `util`.`logCleanMultiConfig` (
`schemaName` varchar(64) NOT NULL,
`tableName` varchar(64) NOT NULL,
`retentionDays` int(11) NOT NULL,
`retentionDays` int(11) DEFAULT NULL,
`order` int(11) DEFAULT NULL,
`started` datetime DEFAULT NULL,
`finished` datetime DEFAULT NULL,
PRIMARY KEY (`schemaName`,`tableName`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
INSERT INTO `util`.`logClean` (`schemaName`, `tableName`, `retentionDays`, `order`)
INSERT INTO `util`.`logCleanMultiConfig` (`schemaName`, `tableName`, `retentionDays`, `order`)
VALUES
('account', 'roleLog', 'xxx', NULL),
('account', 'userLog', 'xxx', NULL),