;;;; SPDX-FileCopyrightText: 2023 Vasilij Schneidermann ;;;; ;;;; SPDX-License-Identifier: GPL-3.0-or-later (module modo-sweep-sessions () (import scheme) (import (chicken base)) (import (chicken process-context)) (import (chicken time)) (import (chicken time posix)) (import sql-de-lite) (define cookie-max-duration (* 365 24 60 60)) (define (utc-timestamp seconds) (time->string (seconds->utc-time seconds) "%Y%m%dT%H%M%SZ")) (define (main db-path) (call-with-database db-path (lambda (db) (let* ((cutoff-timestamp (utc-timestamp (+ (current-seconds) cookie-max-duration))) (deletes (exec (sql db "DELETE FROM sessions WHERE created > ?") cutoff-timestamp))) (print "Swept " deletes " sessions"))))) (apply main (command-line-arguments)) )