Created
December 6, 2012 18:49
-
-
Save karthik/4227024 to your computer and use it in GitHub Desktop.
A function to test API status and return a logical TRUE if it responds.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is required for evalWithTimeout | |
suppressPackageStartupMessages(library(R.utils)) | |
#'Function to test whether an API is down and if so, throw an error. | |
#' | |
#' @param test_fn The function call to test | |
#' @param tlimit = 120 A timeout in seconds | |
#' @return logical | |
#' @examples \dontrun{ | |
#' api_status(eol_search('Salix')) | |
#'} | |
api_status <- function(test_fn, tlimit = 120) { | |
results <- tryCatch(expr = evalWithTimeout(test_fn, timeout = tlimit), TimeoutException = function(ex) "TimedOut") | |
status <- ifelse(is(results, "TimedOut"), FALSE, TRUE) | |
status | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment