Skip to content

Commit

Permalink
fix: (de)serialise schema runtime metadata (#3071)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecthomas authored Oct 10, 2024
1 parent ada88c8 commit 008ee44
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
25 changes: 25 additions & 0 deletions internal/schema/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/alecthomas/types/optional"
"golang.org/x/exp/maps"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"

schemapb "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/schema"
)
Expand Down Expand Up @@ -218,12 +219,27 @@ func (m *Module) Imports() []string {
}

func (m *Module) ToProto() proto.Message {
var runtime *schemapb.ModuleRuntime
if m.Runtime != nil {
runtime = &schemapb.ModuleRuntime{
CreateTime: timestamppb.New(m.Runtime.CreateTime),
Language: m.Runtime.Language,
MinReplicas: m.Runtime.MinReplicas,
}
if m.Runtime.OS != "" {
runtime.Os = &m.Runtime.OS
}
if m.Runtime.Arch != "" {
runtime.Arch = &m.Runtime.Arch
}
}
return &schemapb.Module{
Pos: posToProto(m.Pos),
Builtin: m.Builtin,
Name: m.Name,
Comments: m.Comments,
Decls: declListToProto(m.Decls),
Runtime: runtime,
}
}

Expand All @@ -248,6 +264,15 @@ func ModuleFromProto(s *schemapb.Module) (*Module, error) {
Comments: s.Comments,
Decls: declListToSchema(s.Decls),
}
if s.Runtime != nil {
module.Runtime = &ModuleRuntime{
CreateTime: s.Runtime.GetCreateTime().AsTime(),
Language: s.Runtime.Language,
MinReplicas: s.Runtime.MinReplicas,
OS: s.Runtime.GetOs(),
Arch: s.Runtime.GetArch(),
}
}
return module, ValidateModule(module)
}

Expand Down
19 changes: 19 additions & 0 deletions internal/schema/verb.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/alecthomas/types/optional"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"

schemapb "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/schema"
"github.com/TBD54566975/ftl/internal/slices"
Expand Down Expand Up @@ -152,6 +153,14 @@ func (v *Verb) GetMetadataCronJob() optional.Option[*MetadataCronJob] {
}

func (v *Verb) ToProto() proto.Message {
var runtime *schemapb.VerbRuntime
if v.Runtime != nil {
runtime = &schemapb.VerbRuntime{
CreateTime: timestamppb.New(v.Runtime.CreateTime),
StartTime: timestamppb.New(v.Runtime.StartTime),
Status: schemapb.VerbStatus(v.Runtime.Status),
}
}
return &schemapb.Verb{
Pos: posToProto(v.Pos),
Export: v.Export,
Expand All @@ -160,10 +169,19 @@ func (v *Verb) ToProto() proto.Message {
Request: TypeToProto(v.Request),
Response: TypeToProto(v.Response),
Metadata: metadataListToProto(v.Metadata),
Runtime: runtime,
}
}

func VerbFromProto(s *schemapb.Verb) *Verb {
var runtime *VerbRuntime
if s.Runtime != nil {
runtime = &VerbRuntime{
CreateTime: s.Runtime.CreateTime.AsTime(),
StartTime: s.Runtime.StartTime.AsTime(),
Status: VerbStatus(s.Runtime.Status),
}
}
return &Verb{
Pos: PosFromProto(s.Pos),
Export: s.Export,
Expand All @@ -172,5 +190,6 @@ func VerbFromProto(s *schemapb.Verb) *Verb {
Request: TypeFromProto(s.Request),
Response: TypeFromProto(s.Response),
Metadata: metadataListToSchema(s.Metadata),
Runtime: runtime,
}
}

0 comments on commit 008ee44

Please sign in to comment.