Manual API Speed ​​Limit

I am trying to write a manual speed limit function for a package rgithub. So far this is what I have:

library(rgithub)

pull <- function(i){
 commits <- get.pull.request.commits(owner = owner, repo = repo, id = i, ctx = get.github.context(), per_page=100)
 links <- digest_header_links(commits)
 number_of_pages <- links[2,]$page
 if (number_of_pages != 0)
   try_default(for (n in 1:number_of_pages){
    if (as.integer(commits$headers$`x-ratelimit-remaining`) < 5)
     Sys.sleep(as.integer(commits$headers$`x-ratelimit-reset`)-as.POSIXct(Sys.time()) %>% as.integer())
  else
    get.pull.request.commits(owner = owner, repo = repo, id = i, ctx = get.github.context(), per_page=100, page = n)
}, default = NULL)
else 
   return(commits)
}

list <- c(500, 501, 502)

pull_lists <- lapply(list, pull)

It is assumed that if the variable x-ratelimit-remaininggoes beyond a certain threshold, then the script must wait until the time specified in x-ratelimit-resetpasses, then continue the script. However, I'm not sure if this is the actual behavior of the setup if elseI am here.

, , - . : ) , , ) , , ? , while/?

+4
2

, , 5 Sys.sleep, :

print(system.time(Sys.sleep(...)))

, , , , , rgithub R (3.1.3).

+1

, - .
script, write.csv(append=TRUE).

, ip . jangorecki/Rbitcoin/R/utils.R.
Rbitcoin.last_api_call - env, , .
.

. concurrency read. X .

Edit
, . , , rgithub .. - API.

0

All Articles