Skip to content

Commit

Permalink
feat: compile and schema changes for pubsub (#1600)
Browse files Browse the repository at this point in the history
- adds topics and subscriptions to schema
- extract pubsub declarations from go modules, including which verbs
consume from a subscription
- scaffolds exported topics into `external_module.go`
- this file also now needs to import ftl if there are exported topics as
are included (they call `ftl.RegisterTopic(...)`)
    - `go mod tidy` needs to be called on external modules

Other things of note:

- Topic names must:
- be idents: this allows us to generate external module files with the
variable name as the topic name (with first letter uppercased, so it is
visible to the module)
- start with a lower case letter: this allows us to deterministically
derive the topic name from the generated variable name. (We could remove
this limitation with more work I think, but this was the easiest way I
could derive external topic names)
- Subscription names must be an ident
    - I don't think it'd be too hard to change this one if we want to.
  • Loading branch information
matt2e authored May 30, 2024
1 parent 93f0d7f commit 7fe3075
Show file tree
Hide file tree
Showing 35 changed files with 2,284 additions and 588 deletions.
2 changes: 1 addition & 1 deletion backend/controller/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (c *ConsoleService) GetModules(ctx context.Context, req *connect.Request[pb
Config: c,
})

case *schema.Database, *schema.Enum, *schema.TypeAlias, *schema.FSM:
case *schema.Database, *schema.Enum, *schema.TypeAlias, *schema.FSM, *schema.Topic, *schema.Subscription:
}
}

Expand Down
2 changes: 1 addition & 1 deletion backend/controller/ingress/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func transformAliasedFields(sch *schema.Schema, t schema.Type, obj any, aliaser
}
case *schema.TypeAlias:
return transformAliasedFields(sch, decl.Type, obj, aliaser)
case *schema.Config, *schema.Database, *schema.FSM, *schema.Secret, *schema.Verb:
case *schema.Config, *schema.Database, *schema.FSM, *schema.Secret, *schema.Verb, *schema.Topic, *schema.Subscription:
return fmt.Errorf("%s: unsupported ref type %T", t.Pos, decl)
}

Expand Down
2 changes: 1 addition & 1 deletion backend/controller/ingress/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func validateValue(fieldType schema.Type, path path, value any, sch *schema.Sche
return fmt.Errorf("%s is not a valid variant of enum %s", inputName, fieldType)
}

case *schema.Config, *schema.Database, *schema.Secret, *schema.Verb, *schema.FSM:
case *schema.Config, *schema.Database, *schema.Secret, *schema.Verb, *schema.FSM, *schema.Topic, *schema.Subscription:

}

Expand Down
Loading

0 comments on commit 7fe3075

Please sign in to comment.