Skip to content

Instantly share code, notes, and snippets.

@nathancday
Created September 30, 2020 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathancday/e7a038d70c93169afead1d131ce752cc to your computer and use it in GitHub Desktop.
Save nathancday/e7a038d70c93169afead1d131ce752cc to your computer and use it in GitHub Desktop.
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