Created
September 30, 2020 13:12
-
-
Save nathancday/e7a038d70c93169afead1d131ce752cc to your computer and use it in GitHub Desktop.
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
con <- file("test.log", "at") | |
sink(con, append=T, type = "message") | |
con <- file("test_sleep100.log", "at") | |
sink(con, append=T, type = "message") | |
library(purrr) | |
map(1:100, | |
possibly(function(x) { | |
print(x) | |
message("####") | |
Sys.sleep(100) | |
box_auth_service() | |
message("----") | |
}, "error")) | |
closeAllConnections() | |
# # clean up and reset the kitchen sink | |
# sink(type="message") | |
read_in <- function(file) { | |
x <- readLines(file) | |
idx <- cumsum(x == "####") | |
split(x, idx) %>% | |
map_df( | |
~data.frame( | |
error = any(grepl("status: 400", .)), | |
retries = sum(grepl("Request failed", .)) | |
), | |
.id = "rep" | |
) | |
} | |
library(ggplot2) | |
dir(".", "log$") %>% | |
set_names(c("100 seconds", "10 seconds")) %>% | |
map_df(read_in, .id = "test") %>% | |
ggplot(aes(as.numeric(rep), retries, fill = error)) + | |
geom_col() + | |
facet_grid(test ~ .) + | |
labs(title = "box_auth_service()'s 400 error", | |
subtitle = "Effects of time between requests", | |
y = "# httr retries", | |
x = "# simulated auth attempt") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment