fix: separate worker state from runtime lifecycle
This commit is contained in:
@@ -243,7 +243,10 @@ pub struct WorkerSummary {
|
||||
#[serde(default)]
|
||||
pub tags: Vec<String>,
|
||||
pub workspace: WorkerWorkspaceSummary,
|
||||
/// Runtime catalog lifecycle compatibility state.
|
||||
pub state: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub worker_state: Option<protocol::WorkerStateSnapshot>,
|
||||
pub last_seen_at: Option<String>,
|
||||
#[serde(default)]
|
||||
pub pinned: bool,
|
||||
@@ -335,6 +338,7 @@ pub(crate) fn workspace_worker_summary(
|
||||
workspace_id: summary.workspace.workspace_id,
|
||||
},
|
||||
state: summary.state,
|
||||
worker_state: summary.worker_state,
|
||||
last_seen_at: summary.last_seen_at,
|
||||
pinned: summary.pinned,
|
||||
retention_state: summary.retention_state,
|
||||
@@ -1998,6 +2002,7 @@ impl EmbeddedWorkerRuntime {
|
||||
workspace_id: summary.workspace_id.clone(),
|
||||
},
|
||||
state: embedded_worker_status_label(summary.status).to_string(),
|
||||
worker_state: summary.worker_state.clone(),
|
||||
last_seen_at: None,
|
||||
pinned: false,
|
||||
retention_state: "transient".to_string(),
|
||||
@@ -2037,6 +2042,7 @@ impl EmbeddedWorkerRuntime {
|
||||
workspace_id: detail.workspace_id.clone(),
|
||||
},
|
||||
state: embedded_worker_status_label(detail.status).to_string(),
|
||||
worker_state: detail.worker_state.clone(),
|
||||
last_seen_at: None,
|
||||
pinned: false,
|
||||
retention_state: "transient".to_string(),
|
||||
@@ -3340,6 +3346,7 @@ impl RemoteWorkerRuntime {
|
||||
workspace_id: summary.workspace_id.clone(),
|
||||
},
|
||||
state: embedded_worker_status_label(summary.status).to_string(),
|
||||
worker_state: summary.worker_state.clone(),
|
||||
last_seen_at: None,
|
||||
pinned: false,
|
||||
retention_state: "transient".to_string(),
|
||||
@@ -3383,6 +3390,7 @@ impl RemoteWorkerRuntime {
|
||||
workspace_id: detail.workspace_id.clone(),
|
||||
},
|
||||
state: embedded_worker_status_label(detail.status).to_string(),
|
||||
worker_state: detail.worker_state.clone(),
|
||||
last_seen_at: None,
|
||||
pinned: false,
|
||||
retention_state: "transient".to_string(),
|
||||
@@ -4730,6 +4738,7 @@ pub fn placeholder_worker(host_id: impl Into<String>) -> WorkerSummary {
|
||||
workspace_id: None,
|
||||
},
|
||||
state: "unsupported".to_string(),
|
||||
worker_state: None,
|
||||
last_seen_at: None,
|
||||
pinned: false,
|
||||
retention_state: "transient".to_string(),
|
||||
@@ -5251,6 +5260,7 @@ mod tests {
|
||||
workspace_id: None,
|
||||
},
|
||||
state: "available".to_string(),
|
||||
worker_state: None,
|
||||
last_seen_at: None,
|
||||
pinned: false,
|
||||
retention_state: "transient".to_string(),
|
||||
|
||||
@@ -202,7 +202,16 @@ async fn equal_downstream_selectors_share_one_upstream_subscription() {
|
||||
BrokerSubscriptionEvent::Event {
|
||||
payload: SubscriptionEventPayload::WorkerUpserted { ref worker },
|
||||
..
|
||||
} if worker.state == SubscriptionWorkerState::Running
|
||||
} if worker.state == SubscriptionWorkerState::Idle
|
||||
&& matches!(
|
||||
worker.worker_state,
|
||||
Some(protocol::WorkerStateSnapshot {
|
||||
state: protocol::WorkerState::Busy(protocol::WorkerBusyState::Run(
|
||||
protocol::WorkerRunState::Running
|
||||
)),
|
||||
..
|
||||
})
|
||||
)
|
||||
));
|
||||
}
|
||||
let mut late = broker.subscribe("runtime-test", selector.clone()).unwrap();
|
||||
@@ -212,7 +221,18 @@ async fn equal_downstream_selectors_share_one_upstream_subscription() {
|
||||
assert!(matches!(
|
||||
snapshot,
|
||||
SubscriptionSnapshot::Workers { workers }
|
||||
if workers.iter().any(|worker| worker.state == SubscriptionWorkerState::Running)
|
||||
if workers.iter().any(|worker| {
|
||||
worker.state == SubscriptionWorkerState::Idle
|
||||
&& matches!(
|
||||
worker.worker_state,
|
||||
Some(protocol::WorkerStateSnapshot {
|
||||
state: protocol::WorkerState::Busy(
|
||||
protocol::WorkerBusyState::Run(protocol::WorkerRunState::Running)
|
||||
),
|
||||
..
|
||||
})
|
||||
)
|
||||
})
|
||||
));
|
||||
drop(late);
|
||||
|
||||
@@ -337,8 +357,18 @@ async fn embedded_runtime_uses_in_process_subscription_source() {
|
||||
)
|
||||
.unwrap();
|
||||
assert!(matches!(next_event(&mut subscription).await,
|
||||
BrokerSubscriptionEvent::Event { payload: SubscriptionEventPayload::WorkerUpserted { worker }, .. }
|
||||
if worker.runtime_id.as_deref() == Some("embedded-worker-runtime") && worker.state == SubscriptionWorkerState::Running));
|
||||
BrokerSubscriptionEvent::Event { payload: SubscriptionEventPayload::WorkerUpserted { worker }, .. }
|
||||
if worker.runtime_id.as_deref() == Some("embedded-worker-runtime")
|
||||
&& worker.state == SubscriptionWorkerState::Idle
|
||||
&& matches!(
|
||||
worker.worker_state,
|
||||
Some(protocol::WorkerStateSnapshot {
|
||||
state: protocol::WorkerState::Busy(protocol::WorkerBusyState::Run(
|
||||
protocol::WorkerRunState::Running
|
||||
)),
|
||||
..
|
||||
})
|
||||
)));
|
||||
let mut late = broker
|
||||
.subscribe(
|
||||
"embedded-worker-runtime",
|
||||
@@ -351,7 +381,18 @@ async fn embedded_runtime_uses_in_process_subscription_source() {
|
||||
assert!(matches!(
|
||||
snapshot,
|
||||
SubscriptionSnapshot::Workers { workers }
|
||||
if workers.iter().any(|worker| worker.state == SubscriptionWorkerState::Running)
|
||||
if workers.iter().any(|worker| {
|
||||
worker.state == SubscriptionWorkerState::Idle
|
||||
&& matches!(
|
||||
worker.worker_state,
|
||||
Some(protocol::WorkerStateSnapshot {
|
||||
state: protocol::WorkerState::Busy(
|
||||
protocol::WorkerBusyState::Run(protocol::WorkerRunState::Running)
|
||||
),
|
||||
..
|
||||
})
|
||||
)
|
||||
})
|
||||
));
|
||||
|
||||
runtime
|
||||
|
||||
@@ -15252,6 +15252,7 @@ fn worker_summary_from_registry(record: &WorkerRegistryRecord) -> WorkerSummary
|
||||
singleton_key: None,
|
||||
tags: Vec::new(),
|
||||
state: "missing".to_string(),
|
||||
worker_state: None,
|
||||
last_seen_at: Some(record.updated_at.clone()),
|
||||
pinned: record.retention_state == "pinned",
|
||||
retention_state: record.retention_state.clone(),
|
||||
@@ -24990,6 +24991,7 @@ mod tests {
|
||||
workspace_id: Some(TEST_WORKSPACE_ID.to_string()),
|
||||
},
|
||||
state: "idle".to_string(),
|
||||
worker_state: None,
|
||||
last_seen_at: None,
|
||||
pinned: false,
|
||||
retention_state: "normal".to_string(),
|
||||
@@ -25086,6 +25088,7 @@ mod tests {
|
||||
workspace_id: Some(TEST_WORKSPACE_ID.to_string()),
|
||||
},
|
||||
state: "idle".to_string(),
|
||||
worker_state: None,
|
||||
last_seen_at: None,
|
||||
pinned: false,
|
||||
retention_state: "normal".to_string(),
|
||||
|
||||
Reference in New Issue
Block a user