| 142 | } |
| 143 | |
| 144 | func (s *RuntimeClient) InvokeFunction(input *InvocationInput) (output *InvocationOutput) { |
| 145 | var errorMessage string |
| 146 | reqInfo := s.createRequest(input) |
| 147 | |
| 148 | defer func() { |
| 149 | if errorMessage != "" { |
| 150 | input.Logger.Errorf("invoke function failed, error is %s", errorMessage) |
| 151 | m := innerErr.AwsErrorMessage{ |
| 152 | ErrorMessage: errorMessage, |
| 153 | } |
| 154 | reqInfo.Output.Output.FuncResult = m.String() |
| 155 | } |
| 156 | output = reqInfo.Output |
| 157 | }() |
| 158 | |
| 159 | err := s.waitRuntime(reqInfo) |
| 160 | if err != nil { |
| 161 | errorMessage = fmt.Sprintf("%s wait runtime error: %s", reqInfo.RequestID, err.Error()) |
| 162 | return |
| 163 | } |
| 164 | reqInfo.StepDone(StageWaitRuntime) |
| 165 | |
| 166 | defer func() { |
| 167 | s.invokeCleanup(reqInfo, input.Runtime) |
| 168 | reqInfo.StepDone(StageCleanup) |
| 169 | }() |
| 170 | var logType string |
| 171 | if !api.IsNoneLogType(reqInfo.Input.Configuration.LogType) || |
| 172 | (reqInfo.Input.LogConfig != nil && !api.IsNoneLogType(reqInfo.Input.LogConfig.LogType)) { |
| 173 | logType = string(s.userlogType) |
| 174 | reqInfo.enableUserLog = true |
| 175 | } |
| 176 | |
| 177 | s.startRecvLog(reqInfo, logType) |
| 178 | reqInfo.StepDone(StageStartRecvLog) |
| 179 | reqInfo.Status = StatusRunning |
| 180 | functionTimeout := int(*(input.Configuration.Timeout)) |
| 181 | err = s.InvokeFunc(reqInfo, input) |
| 182 | |
| 183 | timeout := false |
| 184 | if err != nil { |
| 185 | errorMessage = fmt.Sprintf("%s invoke function error: %s", reqInfo.RequestID, err.Error()) |
| 186 | reqInfo.InvokeDone() |
| 187 | reqInfo.StepDone(StageInvokeDone) |
| 188 | reqInfo.InvokeReportDone() |
| 189 | reqInfo.StepDone(StageInvokeReportDone) |
| 190 | s.dispatchServer.StopRecvLog(reqInfo.Runtime.RuntimeID, reqInfo.RequestID, reqInfo.store) |
| 191 | reqInfo.StepDone(StageStopRecvLog) |
| 192 | return |
| 193 | } |
| 194 | |
| 195 | timer := time.NewTimer(time.Duration(functionTimeout) * time.Second) |
| 196 | select { |
| 197 | case <-reqInfo.SyncChannel: |
| 198 | |
| 199 | case <-timer.C: |
| 200 | reqInfo.InvokeResult(StatusTimeout, "Invoke timeout.") |
| 201 | if input.WithStreamMode { |