;;; Nar Herder ;;; ;;; Copyright © 2021 Christopher Baines ;;; ;;; This program is free software: you can redistribute it and/or ;;; modify it under the terms of the GNU Affero General Public License ;;; as published by the Free Software Foundation, either version 3 of ;;; the License, or (at your option) any later version. ;;; ;;; This program is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;;; Affero General Public License for more details. ;;; ;;; You should have received a copy of the GNU Affero General Public ;;; License along with this program. If not, see ;;; . (define-module (nar-herder recent-changes) #:use-module (srfi srfi-1) #:use-module (ice-9 threads) #:use-module (nar-herder database) #:export (start-recent-change-removal-and-database-dump-thread)) (define (start-recent-change-removal-and-database-dump-thread database database-dump-filename check-interval recent-changes-limit) (define (update-database-dump) (let ((temp-database-dump-filename (string-append database-dump-filename ".tmp"))) (when (file-exists? temp-database-dump-filename) (delete-file temp-database-dump-filename)) (dump-database database temp-database-dump-filename) (rename-file temp-database-dump-filename database-dump-filename) (simple-format (current-error-port) "updated database dump\n"))) (call-with-new-thread (lambda () (while #t (let ((recent-changes-id-for-deletion (database-get-recent-changes-id-for-deletion database recent-changes-limit))) (when recent-changes-id-for-deletion (update-database-dump) (let ((deleted-recent-changes (database-delete-recent-changes-with-id-below database recent-changes-id-for-deletion))) (simple-format (current-error-port) "deleted ~A recent changes\n" deleted-recent-changes))) (sleep check-interval))))))