mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
fn: agent call overrider (#1080)
Similar to LB Agent call overrider, this PR adds Agent overrider for Agents to modify/analyze a Call/Extensions during GetCall().
This commit is contained in:
@@ -41,6 +41,9 @@ type Call interface {
|
||||
End(ctx context.Context, err error) error
|
||||
}
|
||||
|
||||
// Interceptor in GetCall
|
||||
type CallOverrider func(*models.Call, map[string]string) (map[string]string, error)
|
||||
|
||||
// TODO build w/o closures... lazy
|
||||
type CallOpt func(c *call) error
|
||||
|
||||
@@ -261,6 +264,16 @@ func (a *agent) GetCall(opts ...CallOpt) (Call, error) {
|
||||
return nil, errors.New("no model or request provided for call")
|
||||
}
|
||||
|
||||
// If overrider is present, let's allow it to modify models.Call
|
||||
// and call extensions
|
||||
if a.callOverrider != nil {
|
||||
ext, err := a.callOverrider(c.Call, c.extensions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.extensions = ext
|
||||
}
|
||||
|
||||
mem := c.Memory + uint64(c.TmpFsSize)
|
||||
if !a.resources.IsResourcePossible(mem, uint64(c.CPUs), c.Type == models.TypeAsync) {
|
||||
// if we're not going to be able to run this call on this machine, bail here.
|
||||
|
||||
Reference in New Issue
Block a user