mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
HTTP Triggers hookup (#1086)
* Initial suypport for invoking tiggers * dupe method * tighten server constraints * runner tests not working yet * basic route tests passing * post rebase fixes * add hybrid support for trigger invoke and tests * consoloidate all hybrid evil into one place * cleanup and make triggers unique by source * fix oops with Agent * linting * review fixes
This commit is contained in:
@@ -17,8 +17,8 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// handleFunctionCall executes the function, for router handlers
|
||||
func (s *Server) handleFunctionCall(c *gin.Context) {
|
||||
// handleV1FunctionCall executes the function, for router handlers
|
||||
func (s *Server) handleV1FunctionCall(c *gin.Context) {
|
||||
err := s.handleFunctionCall2(c)
|
||||
if err != nil {
|
||||
handleV1ErrorResponse(c, err)
|
||||
@@ -40,15 +40,20 @@ func (s *Server) handleFunctionCall2(c *gin.Context) error {
|
||||
}
|
||||
|
||||
appID := c.MustGet(api.AppID).(string)
|
||||
app, err := s.agent.GetAppByID(ctx, appID)
|
||||
app, err := s.lbReadAccess.GetAppByID(ctx, appID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
routePath := path.Clean(p)
|
||||
route, err := s.lbReadAccess.GetRoute(ctx, appID, routePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// gin sets this to 404 on NoRoute, so we'll just ensure it's 200 by default.
|
||||
c.Status(200) // this doesn't write the header yet
|
||||
|
||||
return s.serve(c, app, path.Clean(p))
|
||||
return s.serve(c, app, route)
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -57,7 +62,7 @@ var (
|
||||
|
||||
// TODO it would be nice if we could make this have nothing to do with the gin.Context but meh
|
||||
// TODO make async store an *http.Request? would be sexy until we have different api format...
|
||||
func (s *Server) serve(c *gin.Context, app *models.App, path string) error {
|
||||
func (s *Server) serve(c *gin.Context, app *models.App, route *models.Route) error {
|
||||
buf := bufPool.Get().(*bytes.Buffer)
|
||||
buf.Reset()
|
||||
writer := syncResponseWriter{
|
||||
@@ -75,7 +80,7 @@ func (s *Server) serve(c *gin.Context, app *models.App, path string) error {
|
||||
|
||||
call, err := s.agent.GetCall(
|
||||
agent.WithWriter(&writer), // XXX (reed): order matters [for now]
|
||||
agent.FromRequest(s.agent, app, path, c.Request),
|
||||
agent.FromRequest(app, route, c.Request),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -97,8 +102,7 @@ func (s *Server) serve(c *gin.Context, app *models.App, path string) error {
|
||||
}
|
||||
model.Payload = buf.String()
|
||||
|
||||
// TODO idk where to put this, but agent is all runner really has...
|
||||
err = s.agent.Enqueue(c.Request.Context(), model)
|
||||
err = s.lbEnqueue.Enqueue(c.Request.Context(), model)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user