Hello!
We have an application setup where users can request data to be pulled and updated. I have a post request setup that I want to act as a trigger for starting a data extraction process that can take upwards of 20-30 minutes. I know it is not practical for the requestor to wait that long.
Is there a way to initiate the process with {plumber} and instantly return a 200 while the process runs separately as a promise in another session/process? I tried to see if I could get {promises} to execute in this way, but it will wait the full period before returning a response.
library(plumber)
library(promises)
#* Promise Example
#* @param id:integer ID.
#* @post /promise_exmaple
function(
res,
id
) {
future_promise({
print("Waiting 30 seconds...")
Sys.sleep(30)
print("Waiting is over!")
}) %>%
finally(~ {
## Email to alert user data is ready
})
## While promise is evaluating, return a 200
# msg <- "The request has been queued. You will receive an email when the process is complete."
# res$status <- 200
# return(list(success = msg))
}
Appreciate any help on getting this to work or other solutions for this type of situation!