Wed Jun 29 03:08:25 UTC 2011 pix@kepibu.org
* Wrap drakma:http-request so we can have automatic retries on timeouts
diff -rN -u old-claki/claki.lisp new-claki/claki.lisp
--- old-claki/claki.lisp 2013-07-03 17:13:18.000000000 +0000
+++ new-claki/claki.lisp 2013-07-03 17:13:18.000000000 +0000
@@ -6,13 +6,25 @@
#+(or) (clrhash *last-modified*)
+(defun http-request (&rest drakma-args)
+ "A wrapper around drakma:http-request which automatically retries the request
+in the event of a timeout."
+ (let ((times-failed 0))
+ (tagbody
+ :fetch-page
+ (handler-case (return-from http-request (apply #'drakma:http-request drakma-args))
+ (usocket:timeout-error ()
+ (sleep (* 60 (expt 2 times-failed)))
+ (incf times-failed)
+ (go :fetch-page))))))
+
(defun get-cliki-page (url)
"Returns a page from cliki if it has been modified since we last saw it or nil
if it has not been modified. Signals an error otherwise."
(multiple-value-bind (page status headers)
- (drakma:http-request (format nil "http://cliki.net/~a" url)
- :additional-headers (when (gethash url *last-modified*)
- `((:if-modified-since (gethash url *last-modified*)))))
+ (http-request (format nil "http://cliki.net/~a" url)
+ :additional-headers (when (gethash url *last-modified*)
+ `((:if-modified-since (gethash url *last-modified*)))))
;; FIXME: this doesn't work all that well: it turns out cliki uses a single
;; last-modified header for the entire wiki, rather than one per page, so we
;; aren't saving ourselves (or cliki) much with this.
@@ -176,14 +188,14 @@
(defun revert-page (url current-version to-version)
(multiple-value-bind (page status headers)
- (drakma:http-request (format nil "http://cliki.net/edit/~a" url)
- :method :post
- :parameters `(("version" . ,current-version)
- ("T0" . "BODY")
- ("E0" . ,(get-cliki-source url to-version))
- ("summary" . "Spam detected, reverting to Known-Good.")
- ("captcha" . "lisp")
- ("name" . "Claki (Revertobot Beta)")))
+ (http-request (format nil "http://cliki.net/edit/~a" url)
+ :method :post
+ :parameters `(("version" . ,current-version)
+ ("T0" . "BODY")
+ ("E0" . ,(get-cliki-source url to-version))
+ ("summary" . "Spam detected, reverting to Known-Good.")
+ ("captcha" . "lisp")
+ ("name" . "Claki (Revertobot Beta)")))
(declare (ignore headers))
(cond
((and (= status 200)
@@ -198,7 +210,7 @@
returns the text you should POST to revert a cliki page to the given version."
(or (find-in-cache url version)
(multiple-value-bind (page status headers)
- (drakma:http-request (format nil "http://cliki.net/~a?source&v=~a" url version))
+ (http-request (format nil "http://cliki.net/~a?source&v=~a" url version))
(declare (ignore headers))
(cond
((= 200 status)