Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
matt2e committed Apr 3, 2024
1 parent 54cc407 commit 911c746
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 15 deletions.
2 changes: 1 addition & 1 deletion backend/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions backend/controller/cronjobs/cronjobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions backend/controller/dal/dal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions backend/schema/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
}
Expand Down
1 change: 1 addition & 0 deletions backend/schema/jsonschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
11 changes: 8 additions & 3 deletions backend/schema/metadatacronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package schema

import (
"fmt"
"strconv"
"strings"

"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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),
Expand Down
15 changes: 12 additions & 3 deletions backend/schema/normalise.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion backend/schema/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
}
}

Expand All @@ -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:
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
}
}
Expand Down
1 change: 1 addition & 0 deletions internal/reflect/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 911c746

Please sign in to comment.