Skip to content

Commit

Permalink
component with createdAt (#807)
Browse files Browse the repository at this point in the history
  • Loading branch information
justcoon authored Aug 26, 2024
1 parent 0c5d8ec commit 905b8e3
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 17 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions golem-api-grpc/proto/golem/component/component.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ package golem.component;
import "golem/common/project_id.proto";
import "golem/component/component_metadata.proto";
import "golem/component/versioned_component_id.proto";
import "google/protobuf/timestamp.proto";

message Component {
VersionedComponentId versioned_component_id = 1;
string component_name = 4;
uint64 component_size = 5;
ComponentMetadata metadata = 6;
golem.common.ProjectId project_id = 7;
google.protobuf.Timestamp created_at = 8;
}
3 changes: 3 additions & 0 deletions golem-cli/src/model/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct Component {
pub component_size: u64,
pub metadata: ComponentMetadata,
pub project_id: Option<ProjectId>,
pub created_at: Option<chrono::DateTime<chrono::Utc>>,
}

impl From<golem_client::model::Component> for Component {
Expand All @@ -30,6 +31,7 @@ impl From<golem_client::model::Component> for Component {
component_name,
component_size,
metadata,
created_at,
} = value;

Component {
Expand All @@ -38,6 +40,7 @@ impl From<golem_client::model::Component> for Component {
component_size,
metadata,
project_id: None,
created_at,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions golem-cli/src/model/invoke_result_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ impl InvokeResultView {

#[cfg(test)]
mod tests {
use chrono::Utc;
use golem_wasm_rpc::protobuf::type_annotated_value::TypeAnnotatedValue;
use golem_wasm_rpc::protobuf::TypeAnnotatedValue as RootTypeAnnotatedValue;
use golem_wasm_rpc::protobuf::TypedTuple;
Expand Down Expand Up @@ -156,6 +157,7 @@ mod tests {
memories: vec![],
},
project_id: None,
created_at: Some(Utc::now()),
};

InvokeResultView::try_parse_or_json(
Expand Down
2 changes: 2 additions & 0 deletions golem-component-service-base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ anyhow = { workspace = true }
async-trait = { workspace = true }
bincode = { workspace = true }
bytes = { workspace = true }
chrono = { workspace = true }
http_02 = { workspace = true }
prost = { workspace = true }
prost-types = { workspace = true }
serde = { workspace = true }
sqlx = { workspace = true, features = [
"runtime-tokio",
Expand Down
6 changes: 6 additions & 0 deletions golem-component-service-base/src/model.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use golem_common::model::component_metadata::ComponentMetadata;
use golem_service_base::model::{ComponentName, VersionedComponentId};
use serde::{Deserialize, Serialize};
use std::time::SystemTime;

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Component<Namespace> {
Expand All @@ -9,6 +10,7 @@ pub struct Component<Namespace> {
pub component_name: ComponentName,
pub component_size: u64,
pub metadata: ComponentMetadata,
pub created_at: chrono::DateTime<chrono::Utc>,
}

impl<Namespace> Component<Namespace> {
Expand All @@ -31,6 +33,7 @@ impl<Namespace> From<Component<Namespace>> for golem_service_base::model::Compon
component_name: value.component_name,
component_size: value.component_size,
metadata: value.metadata,
created_at: Some(value.created_at),
}
}
}
Expand All @@ -43,6 +46,9 @@ impl<Namespace> From<Component<Namespace>> for golem_api_grpc::proto::golem::com
component_size: value.component_size,
metadata: Some(value.metadata.into()),
project_id: None,
created_at: Some(prost_types::Timestamp::from(SystemTime::from(
value.created_at,
))),
}
}
}
43 changes: 29 additions & 14 deletions golem-component-service-base/src/repo/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct ComponentRecord {
pub size: i32,
pub version: i64,
pub metadata: Vec<u8>,
pub created_at: chrono::DateTime<chrono::Utc>,
}

impl<Namespace> TryFrom<ComponentRecord> for Component<Namespace>
Expand All @@ -56,6 +57,7 @@ where
component_size: value.size as u64,
metadata,
versioned_component_id,
created_at: value.created_at,
})
}
}
Expand Down Expand Up @@ -84,6 +86,7 @@ where
size: value.component_size as i32,
version: value.versioned_component_id.version as i64,
metadata: metadata.into(),
created_at: value.created_at,
})
}
}
Expand Down Expand Up @@ -167,15 +170,16 @@ impl ComponentRepo for DbComponentRepo<sqlx::Sqlite> {
sqlx::query(
r#"
INSERT INTO component_versions
(component_id, version, size, metadata)
(component_id, version, size, metadata, created_at)
VALUES
($1, $2, $3, $4)
($1, $2, $3, $4, $5)
"#,
)
.bind(component.component_id)
.bind(component.version)
.bind(component.size)
.bind(component.metadata.clone())
.bind(component.created_at)
.execute(&mut *transaction)
.await?;

Expand All @@ -193,7 +197,8 @@ impl ComponentRepo for DbComponentRepo<sqlx::Sqlite> {
c.component_id AS component_id,
cv.version AS version,
cv.size AS size,
cv.metadata AS metadata
cv.metadata AS metadata,
cv.created_at AS created_at
FROM components c
JOIN component_versions cv ON c.component_id = cv.component_id
WHERE c.component_id = $1
Expand All @@ -214,7 +219,8 @@ impl ComponentRepo for DbComponentRepo<sqlx::Sqlite> {
c.component_id AS component_id,
cv.version AS version,
cv.size AS size,
cv.metadata AS metadata
cv.metadata AS metadata,
cv.created_at AS created_at
FROM components c
JOIN component_versions cv ON c.component_id = cv.component_id
WHERE c.namespace = $1
Expand All @@ -238,7 +244,8 @@ impl ComponentRepo for DbComponentRepo<sqlx::Sqlite> {
c.component_id AS component_id,
cv.version AS version,
cv.size AS size,
cv.metadata AS metadata
cv.metadata AS metadata,
cv.created_at AS created_at
FROM components c
JOIN component_versions cv ON c.component_id = cv.component_id
WHERE c.component_id = $1
Expand All @@ -264,7 +271,8 @@ impl ComponentRepo for DbComponentRepo<sqlx::Sqlite> {
c.component_id AS component_id,
cv.version AS version,
cv.size AS size,
cv.metadata AS metadata
cv.metadata AS metadata,
cv.created_at AS created_at
FROM components c
JOIN component_versions cv ON c.component_id = cv.component_id
WHERE c.component_id = $1 AND cv.version = $2
Expand All @@ -290,7 +298,8 @@ impl ComponentRepo for DbComponentRepo<sqlx::Sqlite> {
c.component_id AS component_id,
cv.version AS version,
cv.size AS size,
cv.metadata AS metadata
cv.metadata AS metadata,
cv.created_at AS created_at
FROM components c
JOIN component_versions cv ON c.component_id = cv.component_id
WHERE c.namespace = $1 AND c.name = $2
Expand Down Expand Up @@ -384,15 +393,16 @@ impl ComponentRepo for DbComponentRepo<sqlx::Postgres> {
sqlx::query(
r#"
INSERT INTO component_versions
(component_id, version, size, metadata)
(component_id, version, size, metadata, created_at)
VALUES
($1, $2, $3, $4)
($1, $2, $3, $4, $5)
"#,
)
.bind(component.component_id)
.bind(component.version)
.bind(component.size)
.bind(component.metadata.clone())
.bind(component.created_at)
.execute(&mut *transaction)
.await?;

Expand All @@ -410,7 +420,8 @@ impl ComponentRepo for DbComponentRepo<sqlx::Postgres> {
c.component_id AS component_id,
cv.version AS version,
cv.size AS size,
cv.metadata AS metadata
cv.metadata AS metadata,
cv.created_at::timestamptz AS created_at
FROM components c
JOIN component_versions cv ON c.component_id = cv.component_id
WHERE c.component_id = $1
Expand All @@ -431,7 +442,8 @@ impl ComponentRepo for DbComponentRepo<sqlx::Postgres> {
c.component_id AS component_id,
cv.version AS version,
cv.size AS size,
cv.metadata AS metadata
cv.metadata AS metadata,
cv.created_at::timestamptz AS created_at
FROM components c
JOIN component_versions cv ON c.component_id = cv.component_id
WHERE c.namespace = $1
Expand All @@ -455,7 +467,8 @@ impl ComponentRepo for DbComponentRepo<sqlx::Postgres> {
c.component_id AS component_id,
cv.version AS version,
cv.size AS size,
cv.metadata AS metadata
cv.metadata AS metadata,
cv.created_at::timestamptz AS created_at
FROM components c
JOIN component_versions cv ON c.component_id = cv.component_id
WHERE c.component_id = $1
Expand All @@ -481,7 +494,8 @@ impl ComponentRepo for DbComponentRepo<sqlx::Postgres> {
c.component_id AS component_id,
cv.version AS version,
cv.size AS size,
cv.metadata AS metadata
cv.metadata AS metadata,
cv.created_at::timestamptz AS created_at
FROM components c
JOIN component_versions cv ON c.component_id = cv.component_id
WHERE c.component_id = $1 AND cv.version = $2
Expand All @@ -507,7 +521,8 @@ impl ComponentRepo for DbComponentRepo<sqlx::Postgres> {
c.component_id AS component_id,
cv.version AS version,
cv.size AS size,
cv.metadata AS metadata
cv.metadata AS metadata,
cv.created_at::timestamptz AS created_at
FROM components c
JOIN component_versions cv ON c.component_id = cv.component_id
WHERE c.namespace = $1 AND c.name = $2
Expand Down
7 changes: 6 additions & 1 deletion golem-component-service-base/src/service/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::sync::Arc;
use crate::service::component_compilation::ComponentCompilationService;
use crate::service::component_processor::process_component;
use async_trait::async_trait;
use chrono::Utc;
use golem_common::model::component_metadata::ComponentProcessingError;
use golem_common::model::ComponentId;
use tap::TapFallible;
Expand Down Expand Up @@ -82,6 +83,7 @@ where
component_name: component_name.clone(),
component_size: data.len() as u64,
metadata,
created_at: Utc::now(),
versioned_component_id,
})
}
Expand Down Expand Up @@ -235,7 +237,7 @@ where
namespace: &Namespace,
) -> Result<Component<Namespace>, ComponentError> {
info!(namespace = %namespace, "Update component");

let created_at = Utc::now();
let metadata =
process_component(&data).map_err(ComponentError::ComponentProcessingError)?;

Expand Down Expand Up @@ -266,6 +268,7 @@ where
let component = Component {
component_size,
metadata,
created_at,
..next_component
};
let record = component
Expand Down Expand Up @@ -607,6 +610,7 @@ impl<Namespace: Display + Eq + Clone + Send + Sync> ComponentService<Namespace>
component_id: component_id.clone(),
version: 0,
},
created_at: Utc::now(),
};

Ok(fake_component)
Expand All @@ -631,6 +635,7 @@ impl<Namespace: Display + Eq + Clone + Send + Sync> ComponentService<Namespace>
component_id: component_id.clone(),
version: 0,
},
created_at: Utc::now(),
};

Ok(fake_component)
Expand Down
1 change: 1 addition & 0 deletions golem-service-base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ humantime-serde = { workspace = true }
hyper = { workspace = true }
num-traits = { workspace = true }
poem-openapi = { workspace = true }
prost-types = { workspace = true }
rand = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
Expand Down
Loading

0 comments on commit 905b8e3

Please sign in to comment.