feat: connect runtime worker execution adapter
This commit is contained in:
@@ -22,6 +22,7 @@ thiserror.workspace = true
|
||||
ticket.workspace = true
|
||||
tokio = { workspace = true, features = ["fs", "macros", "net", "rt-multi-thread", "sync"] }
|
||||
tokio-tungstenite.workspace = true
|
||||
worker = { workspace = true, features = ["runtime-adapter"] }
|
||||
worker-runtime = { workspace = true, features = ["ws-server"] }
|
||||
toml.workspace = true
|
||||
tracing.workspace = true
|
||||
|
||||
@@ -917,6 +917,23 @@ impl EmbeddedWorkerRuntime {
|
||||
Self::from_runtime(workspace_id, runtime)
|
||||
}
|
||||
|
||||
pub fn new_memory_with_execution_backend(
|
||||
workspace_id: impl AsRef<str>,
|
||||
backend: std::sync::Arc<dyn worker_runtime::execution::WorkerExecutionBackend>,
|
||||
) -> Result<Self, worker_runtime::error::RuntimeError> {
|
||||
let runtime_id = EmbeddedRuntimeId::new(EMBEDDED_RUNTIME_ID)
|
||||
.expect("embedded runtime id is a non-empty literal");
|
||||
let runtime = worker_runtime::Runtime::with_execution_backend(
|
||||
EmbeddedRuntimeOptions {
|
||||
runtime_id: Some(runtime_id),
|
||||
display_name: Some("Workspace backend embedded Runtime".to_string()),
|
||||
..EmbeddedRuntimeOptions::default()
|
||||
},
|
||||
backend,
|
||||
)?;
|
||||
Ok(Self::from_runtime(workspace_id, runtime))
|
||||
}
|
||||
|
||||
pub fn from_runtime(workspace_id: impl AsRef<str>, runtime: worker_runtime::Runtime) -> Self {
|
||||
let runtime_id = runtime
|
||||
.runtime_id()
|
||||
|
||||
@@ -11,6 +11,7 @@ use axum::{Json, Router};
|
||||
use futures::StreamExt;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::net::TcpListener;
|
||||
use worker::runtime_adapter::WorkerRuntimeExecutionBackend;
|
||||
|
||||
use crate::companion::{
|
||||
CompanionCancelRequest, CompanionConsole, CompanionMessageRequest, CompanionMessageResponse,
|
||||
@@ -97,9 +98,23 @@ impl WorkspaceApi {
|
||||
updated_at: config.workspace_created_at.clone(),
|
||||
})
|
||||
.await?;
|
||||
let mut runtime = RuntimeRegistry::for_workspace(EmbeddedWorkerRuntime::new_memory(
|
||||
config.workspace_id.clone(),
|
||||
));
|
||||
let execution_backend = WorkerRuntimeExecutionBackend::from_workspace(
|
||||
config.workspace_root.clone(),
|
||||
)
|
||||
.map_err(|err| {
|
||||
crate::Error::Store(format!(
|
||||
"failed to initialize embedded Worker backend: {err}"
|
||||
))
|
||||
})?;
|
||||
let mut runtime = RuntimeRegistry::for_workspace(
|
||||
EmbeddedWorkerRuntime::new_memory_with_execution_backend(
|
||||
config.workspace_id.clone(),
|
||||
Arc::new(execution_backend),
|
||||
)
|
||||
.map_err(|err| {
|
||||
crate::Error::Store(format!("invalid embedded Worker backend: {err}"))
|
||||
})?,
|
||||
);
|
||||
for remote_config in config.remote_runtime_sources.iter().cloned() {
|
||||
runtime
|
||||
.register(RemoteWorkerRuntime::new(remote_config).map_err(|err| err.into_error())?);
|
||||
|
||||
Reference in New Issue
Block a user