From hans.huebner at gmail.com Wed Jun 12 19:58:03 2013 From: hans.huebner at gmail.com (=?ISO-8859-1?Q?Hans_H=FCbner?=) Date: Wed, 12 Jun 2013 21:58:03 +0200 Subject: Ignoring timeouts in Drakma In-Reply-To: <5DC4A975-B4A0-49A6-9DE1-68F96B8159CC@mac.com> References: <5DC4A975-B4A0-49A6-9DE1-68F96B8159CC@mac.com> Message-ID: This is not Drakma specific: (defun try-request-from-multiple-urls (&rest urls) (loop (with-simple-restart (try-next "Try next URL") (handler-case (let ((url (first urls))) (format t "requesting ~A~%" url) (return (drakma:http-request url))) (usocket:timeout-error () (setf urls (rest urls)) (unless urls (format t "no more urls, returning~%") (return)) (format t "timeout, trying next url~%") (invoke-restart 'try-next)))))) Tune as desired. If you want to have the last timeout error percolate to the caller, you'll want handler-bind instead. -Hans On Wed, Jun 12, 2013 at 9:42 PM, Patrick May wrote: > I have a list of IP addresses to poll and want to catch the > USOCKET:TIMEOUT-ERROR from Drakma when a machine isn't available, log a > message, and continue on mapping over the list. Does anyone have an > example of how to do this? > > Thanks, > > Patrick > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From patrick.may at mac.com Thu Jun 13 01:33:30 2013 From: patrick.may at mac.com (Patrick May) Date: Wed, 12 Jun 2013 21:33:30 -0400 Subject: Ignoring timeouts in Drakma In-Reply-To: References: <5DC4A975-B4A0-49A6-9DE1-68F96B8159CC@mac.com> <73018FDD-5DFD-4011-9C90-90EF74A4B92F@mac.com> Message-ID: On Jun 12, 2013, at 7:19 PM, Lu?s Oliveira wrote: > On Wed, Jun 12, 2013 at 11:23 PM, Patrick May wrote: >>> (defun try-request-from-multiple-urls (&rest urls) >>> (loop >>> (with-simple-restart (try-next "Try next URL") >>> (handler-case >>> (let ((url (first urls))) >>> (format t "requesting ~A~%" url) >>> (return (drakma:http-request url))) >>> (usocket:timeout-error () >>> (setf urls (rest urls)) >>> (unless urls >>> (format t "no more urls, returning~%") >>> (return)) >>> (format t "timeout, trying next url~%") >>> (invoke-restart 'try-next)))))) >>> >>> Tune as desired. If you want to have the last timeout error percolate to the caller, you'll want handler-bind instead. >> >> Thanks, Hans (and Drew C). I figured out my problem on the train home (debugging by public embarrassment), but your use of with-simple-restart makes the code more understandable so I'll incorporate that. > > Restarts are nice, but usually for communicating with other call > sites. Seems a bit overkill here. If I understand your problem, all > you need is handler-case really. > > (defun poll-urls (urls) > (dolist (url urls) > (handler-case (drakma:http-request url) > (usocket:timeout-error () > (format t "got timeout getting ~A~%" url))))) I ultimately went completely underkill and used ignore-error. I need a shower now. Thanks, Patrick From luismbo at gmail.com Wed Jun 12 23:19:56 2013 From: luismbo at gmail.com (=?ISO-8859-1?Q?Lu=EDs_Oliveira?=) Date: Thu, 13 Jun 2013 00:19:56 +0100 Subject: Ignoring timeouts in Drakma In-Reply-To: <73018FDD-5DFD-4011-9C90-90EF74A4B92F@mac.com> References: <5DC4A975-B4A0-49A6-9DE1-68F96B8159CC@mac.com> <73018FDD-5DFD-4011-9C90-90EF74A4B92F@mac.com> Message-ID: On Wed, Jun 12, 2013 at 11:23 PM, Patrick May wrote: >> (defun try-request-from-multiple-urls (&rest urls) >> (loop >> (with-simple-restart (try-next "Try next URL") >> (handler-case >> (let ((url (first urls))) >> (format t "requesting ~A~%" url) >> (return (drakma:http-request url))) >> (usocket:timeout-error () >> (setf urls (rest urls)) >> (unless urls >> (format t "no more urls, returning~%") >> (return)) >> (format t "timeout, trying next url~%") >> (invoke-restart 'try-next)))))) >> >> Tune as desired. If you want to have the last timeout error percolate to the caller, you'll want handler-bind instead. > > Thanks, Hans (and Drew C). I figured out my problem on the train home (debugging by public embarrassment), but your use of with-simple-restart makes the code more understandable so I'll incorporate that. Restarts are nice, but usually for communicating with other call sites. Seems a bit overkill here. If I understand your problem, all you need is handler-case really. (defun poll-urls (urls) (dolist (url urls) (handler-case (drakma:http-request url) (usocket:timeout-error () (format t "got timeout getting ~A~%" url))))) Cheers, -- Lu?s Oliveira http://r42.eu/~luis/ From patrick.may at mac.com Wed Jun 12 22:23:36 2013 From: patrick.may at mac.com (Patrick May) Date: Wed, 12 Jun 2013 18:23:36 -0400 Subject: Ignoring timeouts in Drakma In-Reply-To: References: <5DC4A975-B4A0-49A6-9DE1-68F96B8159CC@mac.com> Message-ID: <73018FDD-5DFD-4011-9C90-90EF74A4B92F@mac.com> On Jun 12, 2013, at 3:58 PM, Hans H?bner wrote: > This is not Drakma specific: > > (defun try-request-from-multiple-urls (&rest urls) > (loop > (with-simple-restart (try-next "Try next URL") > (handler-case > (let ((url (first urls))) > (format t "requesting ~A~%" url) > (return (drakma:http-request url))) > (usocket:timeout-error () > (setf urls (rest urls)) > (unless urls > (format t "no more urls, returning~%") > (return)) > (format t "timeout, trying next url~%") > (invoke-restart 'try-next)))))) > > Tune as desired. If you want to have the last timeout error percolate to the caller, you'll want handler-bind instead. Thanks, Hans (and Drew C). I figured out my problem on the train home (debugging by public embarrassment), but your use of with-simple-restart makes the code more understandable so I'll incorporate that. Sorry for being too quick to post. Patrick From patrick.may at mac.com Wed Jun 12 19:42:54 2013 From: patrick.may at mac.com (Patrick May) Date: Wed, 12 Jun 2013 15:42:54 -0400 Subject: Ignoring timeouts in Drakma Message-ID: <5DC4A975-B4A0-49A6-9DE1-68F96B8159CC@mac.com> I have a list of IP addresses to poll and want to catch the USOCKET:TIMEOUT-ERROR from Drakma when a machine isn't available, log a message, and continue on mapping over the list. Does anyone have an example of how to do this? Thanks, Patrick