func()

in fc/function.go [81:133]


func (fn *Function) Invoke(req *messages.InvokeRequest, response *messages.InvokeResponse, invokeFuncType functionType) (err error) {
	defer func() {
		if e := recover(); e != nil {
			response.Error = fcPanicResponse(e)
			fn.printPanicLog(req.RequestId, response.Error.ToJson())
			fn.printEndLog(invokeFuncType, req.RequestId, false)
			err = fmt.Errorf("%v", e)
		} else if response.Error != nil {
			fn.printPanicLog(req.RequestId, response.Error.ToJson())
			fn.printEndLog(invokeFuncType, req.RequestId, false)
		} else {
			fn.printEndLog(invokeFuncType, req.RequestId, true)
		}
	}()

	deadline := time.Unix(req.Deadline.Seconds, req.Deadline.Nanos).UTC()
	invokeContext, cancel := context.WithDeadline(fn.context(), deadline)
	defer cancel()
	lc := &req.Context
	lc.RequestID = req.RequestId
	invokeContext = fccontext.NewContext(invokeContext, lc)
	fn.printStartLog(invokeFuncType, req.RequestId)
	if invokeFuncType == initializerFunction {
		if fn.initializeHandler == nil {
			fn.initializeHandler = errorLifeCycleHandler(errors.New("no initializer handler registered"))
		}

		fn.initializeHandler.Invoke(invokeContext)
		return nil
	}

	if invokeFuncType == preFreezeFunction {
		if fn.preFreezeHandler == nil {
			fn.preFreezeHandler = errorLifeCycleHandler(errors.New("no prefreeze handler registered"))
		}
		fn.preFreezeHandler.Invoke(invokeContext)
		return nil
	}

	if invokeFuncType == preStopFunction {
		if fn.preStopHandler == nil {
			fn.preStopHandler = errorLifeCycleHandler(errors.New("no prestop handler registered"))
		}
		fn.preStopHandler.Invoke(invokeContext)
		response.Payload = []byte{}
		return nil
	}

	if fn.funcType == eventFunction {
		return fn.invokeEventFunc(invokeContext, req.Payload, response)
	}
	return fn.invokeHttpFunc(invokeContext, req.HttpParams, req.Payload, response)
}