-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathutils.rs
More file actions
77 lines (68 loc) · 2 KB
/
utils.rs
File metadata and controls
77 lines (68 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use anyhow::Result;
use std::collections::HashMap;
use gas::prelude::*;
use crate::ctx::ApiCtx;
// Re-export types from pegboard for API schema
pub use pegboard::ops::serverless_metadata::fetch::ServerlessMetadataError;
/// Serverless metadata returned from a runner.
#[derive(Debug, Clone)]
pub struct ServerlessMetadata {
pub runtime: String,
pub version: String,
pub actor_names: HashMap<String, serde_json::Value>,
pub envoy_version: Option<u32>,
}
impl From<pegboard::ops::serverless_metadata::fetch::Output> for ServerlessMetadata {
fn from(output: pegboard::ops::serverless_metadata::fetch::Output) -> Self {
ServerlessMetadata {
runtime: output.runtime,
version: output.version,
actor_names: output
.actor_names
.into_iter()
.map(|a| (a.name, serde_json::Value::Object(a.metadata)))
.collect(),
envoy_version: output.envoy_version,
}
}
}
/// Fetches metadata from a serverless runner at the given URL.
///
/// Returns metadata including runtime, version, and actor names if available.
#[tracing::instrument(skip_all)]
pub async fn fetch_serverless_metadata(
ctx: &ApiCtx,
url: String,
headers: HashMap<String, String>,
) -> std::result::Result<ServerlessMetadata, ServerlessMetadataError> {
ctx.op(pegboard::ops::serverless_metadata::fetch::Input { url, headers })
.await
.map_err(|_| ServerlessMetadataError::RequestFailed {})?
.map(ServerlessMetadata::from)
}
/// Fetches metadata from the given URL and populates actor names in the database.
#[tracing::instrument(skip_all)]
pub async fn refresh_runner_config_metadata(
ctx: ApiCtx,
namespace_id: Id,
runner_name: String,
url: String,
headers: HashMap<String, String>,
) -> Result<()> {
tracing::debug!(
?namespace_id,
?runner_name,
"refreshing runner config metadata"
);
ctx.op(pegboard::ops::runner_config::refresh_metadata::Input {
namespace_id,
runner_name,
url,
headers,
})
.await?
.map_err(|e| {
pegboard::errors::ServerlessRunnerPool::FailedToFetchMetadata { reason: e }.build()
})?;
Ok(())
}