Add ability to save state, and some more status prints
Tue Jun 14 18:17:05 UTC 2011 pix@kepibu.org
* Add ability to save state, and some more status prints
hunk ./claki.asd 2
- :depends-on (:oh-ducks :closure-html :cl-unification :drakma :alexandria)
+ :depends-on (:oh-ducks :closure-html :cl-unification :drakma :alexandria :rucksack)
hunk ./claki.lisp 155
+;; TODO?: persist this, so we don't have to care whether cliki remembers it
hunk ./claki.lisp 185
-#+(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")
+[_^L_][_$_]
+(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)