add batch execution

This commit is contained in:
DeniskaRediska committed 2020-06-10 17:15:59 +03:00
1 parent 27c178998c
commit 96be761078
13 files changed
+132 -89

No files matched your search

+5 -36
View File
@@ -1,12 +1,8 @@
package controller
import (
"errors"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"isp-script-service/compile"
"isp-script-service/domain"
"isp-script-service/script"
"isp-script-service/service"
)
var Script scriptController
@@ -14,40 +10,13 @@ var Script scriptController
type scriptController struct{}
func (c scriptController) ExecuteById(req domain.ExecuteByIdRequest) (*domain.ScriptResp, error) {
scr := compile.Script.GetById(req.Id)
if scr == nil {
return nil, status.Errorf(codes.NotFound, "not defined script for id %s", req.Id)
}
return c.executeScript(scr, req.Arg), nil
return service.Script.ExecuteById(req)
}
func (c scriptController) Execute(req domain.ExecuteRequest) *domain.ScriptResp {
scr, err := compile.Script.Create(req.Script)
if err != nil {
return c.respError(err, domain.ErrorCompile)
}
return c.executeScript(scr, req.Arg)
return service.Script.Execute(req)
}
func (c scriptController) executeScript(scr script.Script, arg interface{}) *domain.ScriptResp {
response, err := script.Default().Execute(scr, arg)
if err != nil {
return c.respError(err, domain.ErrorRunTime)
}
if response == nil {
return c.respError(errors.New("empty answer, maybe lost return"), domain.ErrorRunTime)
}
return &domain.ScriptResp{
Result: response,
}
}
func (c scriptController) respError(err error, errorType string) *domain.ScriptResp {
respError := domain.Error{
Type: errorType,
Description: err.Error(),
}
return &domain.ScriptResp{
Error: &respError,
}
func (c scriptController) BatchExecuteById(req domain.BatchExecuteByIdsRequest) []domain.ScriptResp {
return service.Script.BatchExecuteById(req)
}