mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Hybrid plumby (#585)
* fix configuration of agent and server to be future proof and plumb in the hybrid client agent * fixes up the tests, turns off /r/ on api nodes * fix up defaults for runner nodes * shove the runner async push code down into agent land to use client * plumb up async-age * return full call from async dequeue endpoint, since we're storing a whole call in the MQ we don't need to worry about caching of app/route [for now] * fast safe shutdown of dequeue looper in runner / tidying of agent * nice errors for path not found against /r/, /v1/ or other path not found * removed some stale TODO in agent * mq backends are only loud mouths in debug mode now * update tests * Add caching to hybrid client * Fix HTTP error handling in hybrid client. The type switch was on the value rather than a pointer. * Gofmt. * Better caching with a nice caching wrapper * Remove datastore cache which is now unused * Don't need to manually wrap interface methods * Go fmt
This commit is contained in:
@@ -15,22 +15,11 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type runnerResponse struct {
|
||||
RequestID string `json:"request_id,omitempty"`
|
||||
Error *models.ErrorBody `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
// handleFunctionCall executes the function.
|
||||
// Requires the following in the context:
|
||||
// * "app_name"
|
||||
// * "path"
|
||||
func (s *Server) handleFunctionCall(c *gin.Context) {
|
||||
// @treeder: Is this necessary? An app could have this prefix too. Leaving here for review.
|
||||
// if strings.HasPrefix(c.Request.URL.Path, "/v1") {
|
||||
// c.Status(http.StatusNotFound)
|
||||
// return
|
||||
// }
|
||||
|
||||
ctx := c.Request.Context()
|
||||
var p string
|
||||
r := ctx.Value(api.Path)
|
||||
@@ -95,8 +84,8 @@ func (s *Server) serve(c *gin.Context, appName, path string) {
|
||||
}
|
||||
model.Payload = buf.String()
|
||||
|
||||
// TODO we should probably add this to the datastore too. consider the plumber!
|
||||
_, err = s.MQ.Push(c.Request.Context(), model)
|
||||
// TODO idk where to put this, but agent is all runner really has...
|
||||
err = s.Agent.Enqueue(c.Request.Context(), model)
|
||||
if err != nil {
|
||||
handleErrorResponse(c, err)
|
||||
return
|
||||
@@ -106,24 +95,19 @@ func (s *Server) serve(c *gin.Context, appName, path string) {
|
||||
return
|
||||
}
|
||||
|
||||
// Don't serve sync requests from API nodes
|
||||
if s.nodeType != ServerTypeAPI {
|
||||
err = s.Agent.Submit(call)
|
||||
if err != nil {
|
||||
// NOTE if they cancel the request then it will stop the call (kind of cool),
|
||||
// we could filter that error out here too as right now it yells a little
|
||||
if err == models.ErrCallTimeoutServerBusy || err == models.ErrCallTimeout {
|
||||
// TODO maneuver
|
||||
// add this, since it means that start may not have been called [and it's relevant]
|
||||
c.Writer.Header().Add("XXX-FXLB-WAIT", time.Now().Sub(time.Time(model.CreatedAt)).String())
|
||||
}
|
||||
// NOTE: if the task wrote the headers already then this will fail to write
|
||||
// a 5xx (and log about it to us) -- that's fine (nice, even!)
|
||||
handleErrorResponse(c, err)
|
||||
return
|
||||
err = s.Agent.Submit(call)
|
||||
if err != nil {
|
||||
// NOTE if they cancel the request then it will stop the call (kind of cool),
|
||||
// we could filter that error out here too as right now it yells a little
|
||||
if err == models.ErrCallTimeoutServerBusy || err == models.ErrCallTimeout {
|
||||
// TODO maneuver
|
||||
// add this, since it means that start may not have been called [and it's relevant]
|
||||
c.Writer.Header().Add("XXX-FXLB-WAIT", time.Now().Sub(time.Time(model.CreatedAt)).String())
|
||||
}
|
||||
} else {
|
||||
handleErrorResponse(c, models.ErrSyncCallNotSupported)
|
||||
// NOTE: if the task wrote the headers already then this will fail to write
|
||||
// a 5xx (and log about it to us) -- that's fine (nice, even!)
|
||||
handleErrorResponse(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
// TODO plumb FXLB-WAIT somehow (api?)
|
||||
|
||||
Reference in New Issue
Block a user