diff --git a/backend/controller/controller.go b/backend/controller/controller.go index 22cd6db069..709373088c 100644 --- a/backend/controller/controller.go +++ b/backend/controller/controller.go @@ -403,7 +403,7 @@ func (s *Service) UpdateDeploy(ctx context.Context, req *connect.Request[ftlv1.U return nil, fmt.Errorf("%s: %w", "could not set deployment replicas", err) } - s.cronJobs.UpdatedDeploymentMinReplicas(ctx, deploymentKey, int(req.Msg.MinReplicas)) + _ = s.cronJobs.UpdatedDeploymentMinReplicas(ctx, deploymentKey, int(req.Msg.MinReplicas)) return connect.NewResponse(&ftlv1.UpdateDeployResponse{}), nil } diff --git a/backend/controller/cronjobs/cronjobs.go b/backend/controller/cronjobs/cronjobs.go index e26cbec857..1d0bec76ff 100644 --- a/backend/controller/cronjobs/cronjobs.go +++ b/backend/controller/cronjobs/cronjobs.go @@ -92,14 +92,14 @@ func (s *Service) CreatedDeployment(ctx context.Context, deploymentKey model.Dep next, err := gronx.NextTickAfter(schedule, now, false) if err != nil { logger.Errorf(err, "failed to calculate next execution for cron job %v:%v with schedule %q", deploymentKey, verb.Name, schedule) - //TODO: error shouldn't propogate, just log it? + //TODO: error shouldn't propagate, just log it? } else { - new, err := s.dal.CreateCronJob(ctx, deploymentKey, module.Name, verb.Name, schedule, now, next) + created, err := s.dal.CreateCronJob(ctx, deploymentKey, module.Name, verb.Name, schedule, now, next) if err != nil { logger.Errorf(err, "failed to create cron job %v:%v", deploymentKey, verb.Name) //TODO: what should be the error logic? } else { - newJobs = append(newJobs, new) + newJobs = append(newJobs, created) } } } diff --git a/backend/controller/dal/dal.go b/backend/controller/dal/dal.go index ea915d207c..ca0e4e5435 100644 --- a/backend/controller/dal/dal.go +++ b/backend/controller/dal/dal.go @@ -914,10 +914,7 @@ func (d *DAL) GetCronJobs(ctx context.Context) ([]CronJob, error) { if err != nil { return nil, translatePGError(err) } - - return slices.Map(rows, func(row sql.GetCronJobsRow) CronJob { - return cronJobFromRow(row) - }), nil + return slices.Map(rows, cronJobFromRow), nil } func (d *DAL) CreateCronJob(ctx context.Context, deploymentKey model.DeploymentKey, module string, verb string, schedule string, startTime time.Time, nextExecution time.Time) (CronJob, error) { diff --git a/backend/schema/data.go b/backend/schema/data.go index fc6c81aa2b..4c0be18174 100644 --- a/backend/schema/data.go +++ b/backend/schema/data.go @@ -120,6 +120,7 @@ func (d *Data) Monomorphise(ref *Ref) (*Data, error) { IngressPathComponent, *IngressPathLiteral, *IngressPathParameter, *Int, Metadata, *MetadataCalls, *MetadataDatabases, *MetadataIngress, *MetadataCronJob, *MetadataAlias, *Module, *Schema, *String, *Time, Type, *TypeParameter, + *CronJobComponent, *CronJobRange, *CronJobStep, *Unit, *Verb, *Enum, *EnumVariant, Value, *IntValue, *StringValue, Symbol, Named: } diff --git a/backend/schema/jsonschema.go b/backend/schema/jsonschema.go index 8d80752f22..10bffc5721 100644 --- a/backend/schema/jsonschema.go +++ b/backend/schema/jsonschema.go @@ -164,6 +164,7 @@ func nodeToJSSchema(node Node, refs map[RefKey]*Ref) *jsonschema.Schema { case Decl, *Field, Metadata, *MetadataCalls, *MetadataDatabases, *MetadataIngress, *MetadataAlias, IngressPathComponent, *IngressPathLiteral, *IngressPathParameter, *Module, *Schema, Type, *Database, *Verb, *EnumVariant, + *CronJobComponent, *CronJobRange, *CronJobStep, *MetadataCronJob, Value, *StringValue, *IntValue, *Config, *Secret, Symbol, Named: panic(fmt.Sprintf("unsupported node type %T", node)) diff --git a/backend/schema/metadatacronjob.go b/backend/schema/metadatacronjob.go index 5d1807f07b..fcc6fa5739 100644 --- a/backend/schema/metadatacronjob.go +++ b/backend/schema/metadatacronjob.go @@ -2,6 +2,7 @@ package schema import ( "fmt" + "strconv" "strings" "google.golang.org/protobuf/proto" @@ -118,7 +119,7 @@ func (s *CronJobStep) schemaChildren() []Node { func (s *CronJobStep) ToProto() proto.Message { protoStep := &schemapb.CronJobStep{ Pos: posToProto(s.Pos), - Range: s.Range.ToProto().(*schemapb.CronJobRange), + Range: s.Range.toRangeProto(), } if s.Step != nil { stepInt := int64(*s.Step) @@ -169,14 +170,14 @@ func (r *CronJobRange) String() string { if r.End != nil { return fmt.Sprintf("%d-%d", *r.Start, *r.End) } - return fmt.Sprintf("%d", *r.Start) + return strconv.Itoa(*r.Start) } func (r *CronJobRange) schemaChildren() []Node { return nil } -func (r *CronJobRange) ToProto() proto.Message { +func (r *CronJobRange) toRangeProto() *schemapb.CronJobRange { out := &schemapb.CronJobRange{ Pos: posToProto(r.Pos), IsFullRange: r.IsFullRange, @@ -192,6 +193,10 @@ func (r *CronJobRange) ToProto() proto.Message { return out } +func (r *CronJobRange) ToProto() proto.Message { + return r.toRangeProto() +} + func rangeFromProto(r *schemapb.CronJobRange) *CronJobRange { out := &CronJobRange{ Pos: posFromProto(r.Pos), diff --git a/backend/schema/normalise.go b/backend/schema/normalise.go index 9836247bc1..0dec86cc75 100644 --- a/backend/schema/normalise.go +++ b/backend/schema/normalise.go @@ -110,9 +110,6 @@ func Normalise[T Node](n T) T { c.Pos = zero c.Path = normaliseSlice(c.Path) - case *MetadataCronJob: - c.Pos = zero - case *MetadataAlias: c.Pos = zero @@ -125,6 +122,18 @@ func Normalise[T Node](n T) T { case *IngressPathParameter: c.Pos = zero + case *MetadataCronJob: + c.Pos = zero + + case *CronJobComponent: + c.Pos = zero + + case *CronJobRange: + c.Pos = zero + + case *CronJobStep: + c.Pos = zero + case *Config: c.Pos = zero c.Type = Normalise(c.Type) diff --git a/backend/schema/validate.go b/backend/schema/validate.go index f7b95cdc89..99939d33c4 100644 --- a/backend/schema/validate.go +++ b/backend/schema/validate.go @@ -151,6 +151,7 @@ func Validate(schema *Schema) (*Schema, error) { ingress[key] = n case *MetadataCronJob: + //TODO: is this the right place or is validateVerbMetadata the right place? if hasCron { merr = append(merr, errorf(md, "only a single cron schedule is allowed per verb")) continue @@ -162,6 +163,8 @@ func Validate(schema *Schema) (*Schema, error) { if valid := gronx.New().IsValid(schedule); !valid { merr = append(merr, errorf(md, "invalid cron schedule %q", schedule)) } + + case *MetadataCalls, *MetadataDatabases, *MetadataAlias: } } @@ -182,6 +185,7 @@ func Validate(schema *Schema) (*Schema, error) { IngressPathComponent, *IngressPathLiteral, *IngressPathParameter, *Int, *Map, Metadata, *MetadataCalls, *MetadataDatabases, *MetadataIngress, *MetadataAlias, *Module, *Optional, *Schema, + *MetadataCronJob, *CronJobComponent, *CronJobRange, *CronJobStep, *String, *Time, Type, *Unit, *Any, *TypeParameter, *EnumVariant, Value, *IntValue, *StringValue, *Config, *Secret, Symbol, Named: } @@ -313,6 +317,7 @@ func ValidateModule(module *Module) error { *Time, *Map, *Module, *Schema, *String, *Bytes, *MetadataCalls, *MetadataDatabases, *MetadataIngress, *MetadataCronJob, *MetadataAlias, IngressPathComponent, *IngressPathLiteral, *IngressPathParameter, *Optional, + *CronJobComponent, *CronJobRange, *CronJobStep, *Unit, *Any, *TypeParameter, *Enum, *EnumVariant, *IntValue, *StringValue: case Named, Symbol, Type, Metadata, Decl, Value: // Union types. @@ -481,7 +486,8 @@ func validateVerbMetadata(scopes Scopes, n *Verb) (merr []error) { case *IngressPathLiteral: } } - + case *MetadataCronJob: + // TODO: move above cronjob checks to here? case *MetadataCalls, *MetadataDatabases, *MetadataAlias: } } diff --git a/internal/reflect/reflect.go b/internal/reflect/reflect.go index df76d7513a..2174e256dd 100644 --- a/internal/reflect/reflect.go +++ b/internal/reflect/reflect.go @@ -9,6 +9,7 @@ // Package reflect implements the proposal https://go.dev/issue/51520. // // Warning: Not largely tested. Use it with care. +// nolint package reflect import (