I've made an R package (lets call it {myapi}) that defines a plumber API. I've made a separate repo (lets call it {myapi-deploy}) that handles the deployment of the plumber API to Posit Connect. I am having trouble hitting endpoints that use a pooled database connection (defined with pool::dbPool()
). I can successfully call endpoints that don't require a pool
object. I can make a successful database connection on Posit Connect outside of a plumber deployment context.
The {myapi-deploy} repo contains two scripts.
dir/entrypoint.R
:
library(myapi)
library(plumber)
library(pool)
library(noctua)
pool <- dbPool(
drv = noctua::athena(),
catalog = "x",
schema = "x",
s3_staging_dir = 'x',
rstudio_conn_tab = FALSE,
minSize = 1,
maxSize = 100,
idleTimeout = 6000
)
plumb_api(package = "myapi", name = "x") |>
pr_set_debug(TRUE) |>
plumber::pr_hook("exit", function(){
poolClose(pool)
})
deploy.R
:
library(rsconnect)
deployAPI(
"dir",
account = "x",
server = "x"
)
When I attempt to use an endpoint that depends on the pool
object, I get an error like:
{
"error": "500 - Internal server error",
"message": "Error in dplyr::tbl(pool, \"x\"): object 'pool' not found\n"
}
When I run dir/entrypoint.R
in full and use plumber::pr_run()
to deploy locally, the pool
object is initiated and the API calls work. How can I ensure that the pool
object is initiated correctly at runtime on Posit Connect when deploying with rsconnect::deployAPI()
?