Browse code
Finished initial version of the updater.
fiddlerwoaroof authored on 16/10/2015 05:50:45
Showing 1 changed files
Showing 1 changed files
... | ... |
@@ -362,24 +362,41 @@ |
362 | 362 |
(start)) |
363 | 363 |
|
364 | 364 |
(defun update-feed (url) |
365 |
- (wc |
|
365 |
+ (with-whitespace-db |
|
366 | 366 |
(postmodern:with-transaction () |
367 | 367 |
(upsert-feed (make-rss-feed (with-xml-tags (plump:parse (drakma:http-request url)))))))) |
368 | 368 |
|
369 |
+(defmacro amapcar-with-body (list &body forms) |
|
370 |
+ (alexandria:once-only (list) |
|
371 |
+ `(mapcar (lambda (it) ,@forms) |
|
372 |
+ ,list))) |
|
373 |
+ |
|
369 | 374 |
(defun update-all-feeds () |
370 |
- (wc |
|
375 |
+ (with-whitespace-db |
|
371 | 376 |
(let ((urls (postmodern:query (:select 'fetch-url :from 'rss-feed-store)))) |
372 |
- (mapcar (lambda (x) (apply #'update-feed x)) urls)))) |
|
377 |
+ (amapcar-with-body urls |
|
378 |
+ (restart-case |
|
379 |
+ (apply #'update-feed it) |
|
380 |
+ (continue-updates () (warn (format nil "Skipping feed with fetch-url: ~s" it))) |
|
381 |
+ (use-value (v) (update-feed v))))))) |
|
373 | 382 |
|
374 | 383 |
(defun minutes (minutes) (* minutes 60)) |
375 | 384 |
|
385 |
+(defun continue-updates (e) |
|
386 |
+ (declare (ignore e)) |
|
387 |
+ (let ((restart (find-restart 'continue-updates))) |
|
388 |
+ (when restart |
|
389 |
+ (format t "continuing") |
|
390 |
+ (invoke-restart restart)))) |
|
391 |
+ |
|
376 | 392 |
(let (update-thread stop) |
377 | 393 |
(defun start-update-thread () |
378 | 394 |
(setf update-thread |
379 | 395 |
(bordeaux-threads:make-thread |
380 | 396 |
(lambda () |
381 | 397 |
(loop |
382 |
- (update-all-feeds) |
|
398 |
+ (handler-bind ((drakma:parameter-error #'continue-updates)) |
|
399 |
+ (update-all-feeds)) |
|
383 | 400 |
(sleep (ubiquitous:value 'update-frequency)) |
384 | 401 |
(when stop |
385 | 402 |
(return-from nil nil)))) |