Get the result for a single task (see rrq_task_results for a method for efficiently getting multiple results at once). Returns the value of running the task if it is complete, and an error otherwise.
Arguments
- task_id
The single id for which the result is wanted.
- error
Logical, indicating if we should throw an error if a task was not successful. By default (
error = FALSE
), in the case of the task result returning an error we return an object of classrrq_task_error
, which contains information about the error. Passingerror = TRUE
callsstop()
on this error if it is returned.- follow
Optional logical, indicating if we should follow any redirects set up by doing rrq_task_retry. If not given, falls back on the value passed into the controller, the global option
rrq.follow
, and finallyTRUE
. Set toFALSE
if you want to return information about the original task, even if it has been subsequently retried.- controller
The controller to use. If not given (or
NULL
) we'll use the controller registered withrrq_default_controller_set()
.
Value
The result of your task. This may be an error (an object
with class rrq_task_error
) if your task has failed.
Examples
obj <- rrq_controller("rrq:example")
# Create a task, wait for it to finish and fetch its result
t <- rrq_task_create_expr(runif(1), controller = obj)
rrq_task_wait(t, controller = obj)
#> [1] TRUE
rrq_task_result(t, controller = obj)
#> [1] 0.7242312
# Tasks that fail do not fail on result, but instead return an
# object with the class "rrq_task_error"
t <- rrq_task_create_expr(readRDS("somefile.rds"), controller = obj)
rrq_task_wait(t, controller = obj)
#> [1] FALSE
rrq_task_result(t, controller = obj)
#> <rrq_task_error>
#> from: gzfile(file, "rb")
#> error: cannot open the connection
#> queue: rrq:example
#> task: e4abc6863a5ab63b5fa8e693ba7600f7
#> status: ERROR
#> * To throw this error, use stop() with it
#> * This error has a stack trace, use '$trace' to see it
#> * This error has warnings, use '$warnings' to see them