First draft of modifying RunnerListener to CallListener to get it closer to the action (and named better).

This commit is contained in:
Travis Reeder
2017-10-09 18:38:29 -06:00
parent 1ea4872a88
commit a82b6fb1ef
3 changed files with 37 additions and 0 deletions

View File

@@ -209,6 +209,11 @@ func (a *agent) Submit(callI Call) error {
// to make this remove the container asynchronously? // to make this remove the container asynchronously?
defer slot.Close() // notify our slot is free once we're done defer slot.Close() // notify our slot is free once we're done
err = a.fireBeforeCall(ctx, call.Model())
if err != nil {
return fmt.Errorf("BeforeCall: %v", err)
}
// TODO Start is checking the timer now, we could do it here, too. // TODO Start is checking the timer now, we could do it here, too.
err = call.Start(ctx, a) err = call.Start(ctx, a)
if err != nil { if err != nil {

View File

@@ -0,0 +1,31 @@
package extenders
import (
"context"
"github.com/fnproject/fn/api/models"
)
// AppListener is an interface used to inject custom code at key points in app lifecycle.
type AppListener interface {
// BeforeAppCreate called right before creating App in the database
BeforeAppCreate(ctx context.Context, app *models.App) error
// AfterAppCreate called after creating App in the database
AfterAppCreate(ctx context.Context, app *models.App) error
// BeforeAppUpdate called right before updating App in the database
BeforeAppUpdate(ctx context.Context, app *models.App) error
// AfterAppUpdate called after updating App in the database
AfterAppUpdate(ctx context.Context, app *models.App) error
// BeforeAppDelete called right before deleting App in the database
BeforeAppDelete(ctx context.Context, app *models.App) error
// AfterAppDelete called after deleting App in the database
AfterAppDelete(ctx context.Context, app *models.App) error
}
// CallListener enables callbacks around Call events
type CallListener interface {
// BeforeCall called before a function is executed
BeforeCall(ctx context.Context, call *models.Call) error
// AfterCall called after a function completes
AfterCall(ctx context.Context, call *models.Call) error
}

View File

@@ -86,6 +86,7 @@ func (s *Server) serve(c *gin.Context, appName, path string) {
return return
} }
err = doCall(call)
err = s.Agent.Submit(call) err = s.Agent.Submit(call)
if err != nil { if err != nil {
// NOTE if they cancel the request then it will stop the call (kind of cool), // NOTE if they cancel the request then it will stop the call (kind of cool),