MCPcopy Index your code
hub / github.com/FunctionStream/function-stream / StartFunction

Method StartFunction

fs/manager.go:195–248  ·  view source on GitHub ↗
(f *model.Function)

Source from the content-addressed store, hash-verified

193}
194
195func (fm *functionManagerImpl) StartFunction(f *model.Function) error { // TODO: Shouldn't use pointer here
196 if err := f.Validate(); err != nil {
197 return err
198 }
199 fm.functionsLock.Lock()
200 if _, exist := fm.functions[GetNamespacedName(f.Namespace, f.Name)]; exist {
201 fm.functionsLock.Unlock()
202 return common.ErrorFunctionExists
203 }
204 fm.functions[GetNamespacedName(f.Namespace, f.Name)] = make([]api.FunctionInstance, f.Replicas)
205 fm.functionsLock.Unlock()
206 funcCtx := fm.createFuncCtx()
207 for i := int32(0); i < f.Replicas; i++ {
208 runtimeType := f.Runtime.Type
209
210 instanceLogger := fm.log.SubLogger("functionName", f.Name, "instanceIndex", int(i), "runtimeType", runtimeType)
211 instance := fm.options.instanceFactory.NewFunctionInstance(f, funcCtx, i, instanceLogger)
212 fm.functionsLock.Lock()
213 fm.functions[GetNamespacedName(f.Namespace, f.Name)][i] = instance
214 fm.functionsLock.Unlock()
215 runtimeFactory, err := fm.getRuntimeFactory(runtimeType)
216 if err != nil {
217 return err
218 }
219 var sources []<-chan contube.Record
220 for _, t := range f.Sources {
221 sourceFactory, err := fm.getTubeFactory(&t)
222 if err != nil {
223 return nil
224 }
225 sourceChan, err := sourceFactory.NewSourceTube(instance.Context(), t.Config)
226 if err != nil {
227 return fmt.Errorf("failed to create source event queue: %w", err)
228 }
229 sources = append(sources, sourceChan)
230 }
231 sinkFactory, err := fm.getTubeFactory(&f.Sink)
232 if err != nil {
233 return nil
234 }
235 sink, err := sinkFactory.NewSinkTube(instance.Context(), f.Sink.Config)
236 if err != nil {
237 return fmt.Errorf("failed to create sink event queue: %w", err)
238 }
239
240 runtime, err := runtimeFactory.NewFunctionRuntime(instance)
241 if err != nil {
242 return fmt.Errorf("failed to create runtime: %w", err)
243 }
244
245 go instance.Run(runtime, sources, sink)
246 }
247 return nil
248}
249
250func (fm *functionManagerImpl) DeleteFunction(namespace, name string) error {
251 fm.functionsLock.Lock()

Callers

nothing calls this directly

Calls 12

createFuncCtxMethod · 0.95
getRuntimeFactoryMethod · 0.95
getTubeFactoryMethod · 0.95
ContextMethod · 0.95
RunMethod · 0.95
GetNamespacedNameFunction · 0.85
ValidateMethod · 0.80
SubLoggerMethod · 0.80
NewFunctionInstanceMethod · 0.65
NewSourceTubeMethod · 0.65
NewSinkTubeMethod · 0.65
NewFunctionRuntimeMethod · 0.65

Tested by

no test coverage detected