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

[Feature Request] return mirai objects from everywhere() #164

Open
dgkf opened this issue Nov 5, 2024 · 2 comments
Open

[Feature Request] return mirai objects from everywhere() #164

dgkf opened this issue Nov 5, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@dgkf
Copy link

dgkf commented Nov 5, 2024

I've finally landed on a good project for experimenting with mirai and I've been super impressed.

All was going well until I started getting errors in some code I was calling with everywhere(). Not any issue with mirai directly - it turns out a web request I needed to make from each node was starting to error due to some server downtime. To debug the issues in everywhere(), I had to re-write it as single mirai() call to inspect the result.

It would be helpful if everywhere() returned a list of mirai objects similar to mirai_map. This would allow me to build some checks into my scripts for situations where successful execution relies on external factors.

daemons(2)
ms <- everywhere({ 
  do_flaky_web_request()
  "success"
})

ms[]
ms[[1]]$data
#> [1] "success"

ms[[2]]$data
#> 'miraiError' chr Error in do_flaky_web_request: server timeout
@dgkf
Copy link
Author

dgkf commented Nov 6, 2024

For the time being, I did something really hacky to return the vector of mirai connections already stored in everywhere():

mirai/R/mirai.R

Line 268 in 92afc17

invisible()

-   invisible()
+   invisible(vec)
# modify `everywhere()` to return `vec`
everywhere <- mirai::everywhere
body(everywhere) <- bquote({ .(body(everywhere)); invisible(vec) })

ms <- mirai::collect_mirai(everywhere({
  do_flaky_web_request()
  "success"
}))

if (any(is_error <- vapply(ms, mirai::is_mirai_error, logical(1L)))) {
  stop("issues encountered during daemon setup")
}

This let me terminate early when anything goes wrong. In practice, I can also expose things like individual node error messages and stack traces stored in the mirai error objects.

Although modifying a function body is a last resort, I was impressed by how simple the change was.

@shikokuchuo
Copy link
Owner

Thanks Doug. I'm persuaded of the benefits of your request.

Leave this with me - it may take some time as I might be updating the underlying implementation (currently comprised of mirai calls) - and I don't want to be changing the API too often.

@shikokuchuo shikokuchuo added the enhancement New feature or request label Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants