runtime: restore persisted worker execution

This commit is contained in:
2026-07-12 23:38:56 +09:00
parent c56b8c04ea
commit c948b669c1
6 changed files with 727 additions and 56 deletions
+38
View File
@@ -61,6 +61,7 @@ pub enum WorkerExecutionRunState {
#[serde(rename_all = "snake_case")]
pub enum WorkerExecutionOperation {
Spawn,
Restore,
Input,
Stop,
Cancel,
@@ -291,6 +292,20 @@ pub struct WorkerExecutionSpawnRequest {
pub config_bundle: Option<ConfigBundle>,
}
/// Restore request passed to an execution backend for a persisted Runtime Worker.
///
/// The persisted execution status is a restore hint, not a live handle. Backends
/// must create a fresh controller/handle before returning `Connected`.
#[derive(Clone, Debug)]
pub struct WorkerExecutionRestoreRequest {
pub worker_ref: WorkerRef,
pub request: CreateWorkerRequest,
pub context: WorkerExecutionContext,
pub previous_execution: WorkerExecutionStatus,
pub working_directory: Option<WorkingDirectoryBinding>,
pub config_bundle: Option<ConfigBundle>,
}
/// Result of backend Worker spawn/initialization.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum WorkerExecutionSpawnResult {
@@ -313,6 +328,16 @@ pub trait WorkerExecutionBackend: Send + Sync + 'static {
fn spawn_worker(&self, request: WorkerExecutionSpawnRequest) -> WorkerExecutionSpawnResult;
fn restore_worker(
&self,
_request: WorkerExecutionRestoreRequest,
) -> WorkerExecutionSpawnResult {
WorkerExecutionSpawnResult::Rejected(WorkerExecutionResult::unsupported(
WorkerExecutionOperation::Restore,
"execution backend does not support restoring workers",
))
}
fn create_working_directory(
&self,
_request: &WorkingDirectoryRequest,
@@ -394,6 +419,19 @@ impl WorkerExecutionBackendRef {
self.backend.spawn_worker(request)
}
#[cfg(feature = "fs-store")]
pub(crate) fn backend_id(&self) -> &str {
&self.id
}
#[cfg(feature = "fs-store")]
pub(crate) fn restore_worker(
&self,
request: WorkerExecutionRestoreRequest,
) -> WorkerExecutionSpawnResult {
self.backend.restore_worker(request)
}
pub(crate) fn create_working_directory(
&self,
request: &WorkingDirectoryRequest,