blob: fee63f3b32a419d8fc9a828f96c003e893a61b9e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
;;; Nar Herder
;;;
;;; Copyright © 2021 Christopher Baines <mail@cbaines.net>
;;;
;;; 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
;;; <http://www.gnu.org/licenses/>.
(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))))))
|