zhuravljov / yii2-queue-monitor

Yii2 Queue Analytics Module
BSD 3-Clause "New" or "Revised" License
102 stars 24 forks source link

garbage collecting #15

Closed mihan007 closed 5 years ago

mihan007 commented 5 years ago

Do this great package supports some kind of garbage collecting? I mean removing info about execution/.. etc older than day/week/month? Or I need to implement it manually?

I just don't like the idea of increasing db's backups.

Insolita commented 5 years ago

no; you can easy make this functional manually; tables from this module can be safely excluded from backup, it as logs only

zhuravljov commented 5 years ago

I'm going to make console command to clear deprecated logs.

mihan007 commented 5 years ago

Thanks. Looking forward to get it.

zhuravljov commented 5 years ago

Done. https://github.com/zhuravljov/yii2-queue-monitor/blob/master/README.md#console

But you can use DB-specified solutions also. MySQL routines-based solution look like as:

DROP PROCEDURE IF EXISTS clear_queue_monitor_deprecated_records;
DELIMITER ;;
CREATE PROCEDURE clear_queue_monitor_deprecated_records(
    IN in_min_time TIMESTAMP
)
    SQL SECURITY INVOKER
    MODIFIES SQL DATA
    COMMENT 'Procedure to clear deprecated rows using min time param.'
BEGIN
    DELETE exec.*
    FROM queue_exec exec
    INNER JOIN queue_push push ON push.id = exec.push_id
    WHERE push.pushed_at < UNIX_TIMESTAMP(in_min_time);

    DELETE
    FROM queue_push
    WHERE pushed_at < UNIX_TIMESTAMP(in_min_time);
END;;
DELIMITER ;

DROP EVENT IF EXISTS event_to_clear_queue_monitor_deprecated_records;
CREATE EVENT event_to_clear_queue_monitor_deprecated_records
    ON SCHEDULE EVERY '1' HOUR
    ON COMPLETION PRESERVE
    ENABLE
    COMMENT 'Event to clear deprecated rows that clears rows one day older.'
    DO CALL clear_queue_monitor_deprecated_records(NOW() - INTERVAL 1 DAY);
zhuravljov commented 5 years ago

monitor/clear-deprecated command should be used with --silent or --interactive=0 param if you run its by crontab.

mihan007 commented 5 years ago

Thanks