Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the availability to plumber in order to start it without blocking the r process #451

Closed
andraspetrik opened this issue Jun 15, 2019 · 11 comments
Labels
knowledge 🤯 Learn about common {plumber} problems

Comments

@andraspetrik
Copy link

Add the avaiability to start plumber without blocking like httpuv::startServer()

@schloerke
Copy link
Collaborator

@andraspetrik
What are you trying to achieve that isn't already available in the plumber router object?

@schloerke schloerke added the need info Further information has been requested label Jun 17, 2019
@blairj09
Copy link
Collaborator

blairj09 commented Aug 8, 2019

This can be accomplished using RStudio background jobs. See example here: https://github.com/sol-eng/background-jobs/tree/master/plumber-job
There's also an associated issue to make this a native part of the RStudio IDE:
rstudio/rstudio#5190

@kurt-o-sys
Copy link

I'm want to write some api tests. So, whenever I run the plumber server, the tests hang because it blocks. Is there a way to write tests on plumber-api's ? (If plumber wouldn't be blocking after startup, this would be rather straight forward)

@meztez
Copy link
Collaborator

meztez commented Jun 29, 2020

What is done internally is call the Plumber R6 $ methods directly instead of running the server.
Depending on what you want to do this might work. You can look in the testthat folder in tests for the file test-plumber.R

pr$route(make_req("GET", "/nested/path"), res)

make_req <- function(verb, path, qs="", body=""){

You could do something like that.

pr <- plumb("plumber.R")
req <- #create a mock req object or save one from a sample and load it.
pr$call(req)

It will mostly do the same thing without the running server part like.

@blairj09
Copy link
Collaborator

blairj09 commented Jul 1, 2020

There's an example here that uses callr to run Plumber in the background so that tests can be run against it.

@schloerke schloerke added knowledge 🤯 Learn about common {plumber} problems and removed need info Further information has been requested labels Sep 25, 2020
@layik
Copy link

layik commented Oct 13, 2020

Hoping @blairj09 or @schloerke may have a solution. So the "call" method is not the right ("running") way to do this and although I had successfully gone the callr::r_bg way I now get this error from running:

https://github.com/ATFutures/geoplumber/blob/17f07ada3fe47ae81319c49d1299a1c96305aff6/R/plumb.R#L69

callr subprocess failed: "rs_plumberviewer" not available for .Call() for package "(embedding)"

Will update this closed ticket if I find the cause/fix myself. Thanks

@meztez
Copy link
Collaborator

meztez commented Oct 13, 2020

The visual documentation is now enabled in interactive mode. You are probably running inside RStudio and your plumber option options("plumber.swagger.url") is set to call rs_plumberViewer.

You could disable the callback or disable the visual documentation.

That would be my hypothesis as rs_plumberviewer is what RStudio use to open plumber visual documentation.

@meztez
Copy link
Collaborator

meztez commented Oct 13, 2020

f <- function(s, p, h) s$run(port = p, host = h)

replace with below to set docs callback to null (visual documentation will still be available)

f <- function(s, p, h) { s$setDocsCallback(); s$run(port = p, host = h)}

or to remove visual documentation entirely

f <- function(s, p, h) { s$setDocs(FALSE); s$run(port = p, host = h)}

@layik
Copy link

layik commented Oct 13, 2020

Thank you very much @meztez! Can I help documenting this somewhere better for everyone else? Apologies for the single letter codes will revamp it now that I think plumber is stable to move forward.

@meztez
Copy link
Collaborator

meztez commented Oct 13, 2020

This is more of an RStudio problem though... don't know where you would document that.

See third breaking change : https://www.rplumber.io/news/index.html#breaking-changes

@layik
Copy link

layik commented Oct 13, 2020

Maybe I need to understand the actual issue rather than jumping to contribute. Thanks again @meztez

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
knowledge 🤯 Learn about common {plumber} problems
Projects
None yet
Development

No branches or pull requests

6 participants