mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
* fn: reduce lbagent and agent dependency lbagent and agent code is too dependent. This causes any changed in agent to break lbagent. In reality, for LB there should be no delegated agent. Splitting these two will cause some code duplication, but it reduces dependency and complexity (eg. agent without docker) * fn: post rebase fixup * fn: runner/runnercall should use lbDeadline * fn: fixup ln agent test * fn: remove agent create option for common.WaitGroup
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package agent
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/fnproject/fn/api/models"
|
|
"github.com/fnproject/fn/fnext"
|
|
)
|
|
|
|
type callTrigger interface {
|
|
fireBeforeCall(context.Context, *models.Call) error
|
|
fireAfterCall(context.Context, *models.Call) error
|
|
}
|
|
|
|
func (a *agent) AddCallListener(listener fnext.CallListener) {
|
|
a.callListeners = append(a.callListeners, listener)
|
|
}
|
|
|
|
func (a *agent) fireBeforeCall(ctx context.Context, call *models.Call) error {
|
|
return fireBeforeCallFun(a.callListeners, ctx, call)
|
|
}
|
|
|
|
func (a *agent) fireAfterCall(ctx context.Context, call *models.Call) error {
|
|
return fireAfterCallFun(a.callListeners, ctx, call)
|
|
}
|
|
|
|
func fireBeforeCallFun(callListeners []fnext.CallListener, ctx context.Context, call *models.Call) error {
|
|
for _, l := range callListeners {
|
|
err := l.BeforeCall(ctx, call)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func fireAfterCallFun(callListeners []fnext.CallListener, ctx context.Context, call *models.Call) error {
|
|
for _, l := range callListeners {
|
|
err := l.AfterCall(ctx, call)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|