Files
fn-serverless/api/runnerpool/fake_placer.go
Andrea Rosa 182db94fad Feature/acksync response writer (#1267)
This implements a "detached" mechanism to get an ack from the runner
once it actually starts to run a function. In this scenario the response
returned back is just a 202 if we placed the function in a specific
time-frame. If we hit some errors or we fail to place the fn in time we
return back different errors.
2018-11-09 10:25:43 -08:00

35 lines
902 B
Go

package runnerpool
import (
"context"
"time"
)
type fakeDetachedPlacer struct {
cfg PlacerConfig
sleeptime time.Duration
}
func NewFakeDetachedPlacer(cfg *PlacerConfig, st time.Duration) Placer {
return &fakeDetachedPlacer{
cfg: *cfg,
sleeptime: st,
}
}
func (p *fakeDetachedPlacer) GetPlacerConfig() PlacerConfig {
return p.cfg
}
// PlaceCall for the fakeDetachedPlacer just sleeps for a period of time to let the placer context to time out.
// It returns the context exceeded error only if the placer context times out and the request context is still valid
func (p *fakeDetachedPlacer) PlaceCall(ctx context.Context, rp RunnerPool, call RunnerCall) error {
state := NewPlacerTracker(ctx, &p.cfg, call)
defer state.HandleDone()
time.Sleep(p.sleeptime)
if state.placerCtx.Err() != nil && state.requestCtx.Err() == nil {
return state.placerCtx.Err()
}
return nil
}