| Title: | 'rtemis' Server |
|---|---|
| Description: | Create a websocket server to run 'rtemis' functions from an 'rtemislive' client. |
| Authors: | E.D. Gennatas [aut, cre, cph] (ORCID: <https://orcid.org/0000-0001-9280-3609>) |
| Maintainer: | E.D. Gennatas <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.0.6 |
| Built: | 2026-05-27 18:09:45 UTC |
| Source: | https://github.com/rtemis-org/rtemis.server |
Local WebSocket server that bridges browser-based rtemislive clients
to a persistent R session running rtemis. See vignette("rtemislive")
(TODO) and specs/ for the wire protocol.
rtemis.server: rtemis WebSocket server
Maintainer: E.D. Gennatas [email protected] (ORCID) [copyright holder]
Authors:
E.D. Gennatas [email protected] (ORCID) [copyright holder]
Useful links:
Report bugs at https://github.com/rtemis-org/rtemis.server/issues
rtemis::train progress checkpoint over the msg sinkThin adapter passed as progress = to rtemis::train(). Calls
rtemis's internal msg() with caller = stage, so the daemon-side
sink (installed by init_daemon_progress) ships an envelope whose
caller field carries the structured stage name (e.g.
"outer_fold"). The host turns that into a job.progress event with
data$stage set, which the UI can route on without text-matching
the message.
forward_progress(stage, current, total, message)forward_progress(stage, current, total, message)
stage |
Character scalar: Structured stage name. Becomes the
|
current |
Integer: 1-based index of the checkpoint. Unused by
this adapter directly (encoded into |
total |
Integer: Total checkpoints. Same as |
message |
Character scalar: Human-readable line, e.g.
|
msg is unexported from rtemis; the reference is bound at package
source-eval time in 00_init.R via getFromNamespace, so calling
msg() here avoids both rtemis:::msg (R CMD check NOTE) and any
per-call namespace lookup.
Designed to be referenced as rtemis.server::forward_progress inside
the mirai job expression - mirai loads rtemis.server on the daemon
on first use, sourcing 00_init.R once, so the msg binding exists
before the callback is ever invoked.
Invisible NULL.
EDG
Launches a local-only WebSocket server that bridges the rtemislive browser frontend to a persistent R session running rtemis. Provides async training, real-time progress, structured result transfer, and session-aware state across reconnects.
serve( port = NULL, host = "127.0.0.1", n_daemons = 1L, origins = NULL, token = NULL, heartbeat_interval = 5, session_ttl = 86400, data_ttl = 3600, gc_interval = 60, tick_ms = 50L, max_concurrent = n_daemons, max_sessions = 16L, verbosity = 1L )serve( port = NULL, host = "127.0.0.1", n_daemons = 1L, origins = NULL, token = NULL, heartbeat_interval = 5, session_ttl = 86400, data_ttl = 3600, gc_interval = 60, tick_ms = 50L, max_concurrent = n_daemons, max_sessions = 16L, verbosity = 1L )
port |
Integer: TCP port to listen on. Must be in |
host |
Character: Bind address. Defaults to |
n_daemons |
Integer: Number of mirai worker processes. Default
|
origins |
Optional character vector: Allowed |
token |
Optional character scalar: Auth token clients must
present. |
heartbeat_interval |
Numeric, seconds: Heartbeat tick rate. |
session_ttl |
Numeric, seconds: Idle-session GC TTL. |
data_ttl |
Numeric, seconds: Idle-data-handle GC TTL. |
gc_interval |
Numeric, seconds: How often GC runs. |
tick_ms |
Integer milliseconds: Background tick rate for the
non-WS periodic work scheduled via |
max_concurrent |
Integer: Cap on concurrent jobs across all
sessions. Defaults to |
max_sessions |
Integer: Cap on the number of sessions. |
verbosity |
Integer: |
Blocks until the user interrupts (Ctrl-C) or another mechanism sets
server$stop_requested. See specs/rtemislive.md for the wire
protocol and architectural details.
Server env, invisibly. Returned after the loop exits so callers (notably tests running the server on a mirai task) can inspect state.
EDG
## Not run: # Run on the default port; Ctrl-C to stop. serve() # Multiple workers for a multi-user setup (each job gets fewer cores). serve( port = 5757L, n_daemons = 4L, origins = c("http://localhost:3000"), token = "abcd-1234-ef56-7890" ) ## End(Not run)## Not run: # Run on the default port; Ctrl-C to stop. serve() # Multiple workers for a multi-user setup (each job gets fewer cores). serve( port = 5757L, n_daemons = 4L, origins = c("http://localhost:3000"), token = "abcd-1234-ef56-7890" ) ## End(Not run)
Sets server$stop_requested. On its next tick the loop will close
the HTTP listener (which causes http_server$serve() to return) and
serve() cleans up daemons and sockets via on.exit.
shutdown(server)shutdown(server)
server |
Server env returned (or shared) from |
Useful when the server runs on a mirai task or a separate R process that can be passed the server env (e.g. in integration tests). For a server running in the user's foreground R session, just press Ctrl-C.
NULL, invisibly.
EDG
## Not run: # Start the server on a mirai task so it doesn't block the session. task <- mirai::mirai({ rtemis.server::serve(port = 5757L, verbosity = 0L) }) # ... do work ... # Signal the server to stop gracefully. rtemis.server::shutdown(task$data) ## End(Not run)## Not run: # Start the server on a mirai task so it doesn't block the session. task <- mirai::mirai({ rtemis.server::serve(port = 5757L, verbosity = 0L) }) # ... do work ... # Signal the server to stop gracefully. rtemis.server::shutdown(task$data) ## End(Not run)