Tue Jun 14 18:17:05 UTC 2011 pix@kepibu.org * Add ability to save state, and some more status prints diff -rN -u old-claki/claki.asd new-claki/claki.asd --- old-claki/claki.asd 2016-02-16 17:55:49.000000000 +0000 +++ new-claki/claki.asd 2016-02-16 17:55:49.000000000 +0000 @@ -1,3 +1,3 @@ (defsystem :claki - :depends-on (:oh-ducks :closure-html :cl-unification :drakma :alexandria) + :depends-on (:oh-ducks :closure-html :cl-unification :drakma :alexandria :rucksack) :components ((:file "claki"))) diff -rN -u old-claki/claki.lisp new-claki/claki.lisp --- old-claki/claki.lisp 2016-02-16 17:55:49.000000000 +0000 +++ new-claki/claki.lisp 2016-02-16 17:55:49.000000000 +0000 @@ -152,6 +152,7 @@ page) (t nil)))) +;; TODO?: persist this, so we don't have to care whether cliki remembers it (defun get-cliki-source (url version) "Fetches the source text of a given version of a cliki page. That is, it returns the text you should POST to revert a cliki page to the given version." @@ -181,4 +182,37 @@ (defun minutes (m) (* (seconds 60) m)) (defun hours (h) (* (minutes 60) h)) -#+(or) (dotimes (i 4) (sleep (minutes 30)) (unattented-revert-new-spam)) +(defconstant +simple-time+ '(:year #\- :month #\- :day #\Space :hour #\: :min #\: :sec)) + +(defun run-for-a-while () + (dotimes (i 20) + (sleep (minutes (+ 25 (random 10)))) + (format t "; Unattented run at ~a~%" (local-time:format-timestring nil (local-time:now) :format +simple-time+)) + (unattended-revert-new-spam) + (save-state))) + +#+(or) (sb-thread:make-thread #'run-for-a-while :name "cliki reverter") + +(defvar *state-file* (or #.*load-pathname* #p"/home/pixel/repos/claki/state/")) + +(defun save-state () + (rucksack:with-rucksack (rs *state-file*) + (rucksack:with-transaction () + (unless (rs:rucksack-roots rs:*rucksack*) + (rs:add-rucksack-root (make-instance 'rs:btree :key< 'string<) rs:*rucksack*)) + (let ((btree (first (rs:rucksack-roots rs:*rucksack*)))) + (rs:btree-insert btree 'spam-urls *spam-urls*) + (rs:btree-insert btree 'ham-urls *okay-urls*) + (rs:btree-insert btree 'known-good *last-known-good*))))) + +#+(or) (save-state) + +(defun restore-state () + (rs:with-rucksack (rs *state-file*) + (rs:with-transaction () + (let ((btree (first (rs:rucksack-roots rs:*rucksack*)))) + (setf *spam-urls* (rs:btree-search btree 'spam-urls) + *okay-urls* (rs:btree-search btree 'ham-urls) + *last-known-good* (rs:btree-search btree 'known-good)))))) + +#+(or) (restore-state)