Skip to content

Instantly share code, notes, and snippets.

@GeorgeOduor
Last active December 29, 2020 05:24
Show Gist options
  • Save GeorgeOduor/35a694c86acc75a92aa114c43059ae14 to your computer and use it in GitHub Desktop.
Save GeorgeOduor/35a694c86acc75a92aa114c43059ae14 to your computer and use it in GitHub Desktop.
# want to keep retryng until a condition is met then run your script?here you go......
library(futile.logger)
library(utils)
eod_check <- function(){
eod_file = readxl::read_excel('D:/test.xlsx')
return(eod_file$Status)
}
retry_until <- function(expr, maxErrors=5, sleep=0) {
retval = try(eval(expr))
while (T) {
until = eod_check()
if (until) {
msg = "Condtion is met do something"
message(msg)
break()
} else {
msg = "Condition isnt done yet but i will retry"
flog.error(msg)
# warning(msg)
}
if (sleep > 0) Sys.sleep(sleep)
retval = try(eval(expr))
}
return(retval)
}
retry_until(3+3,sleep = 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment