Merge branch 'add_batch_method' into 'master'
additional batch method See merge request integration-system/isp-script-service!4
This commit is contained in:
commit
68e1f0d094
5 files changed
+28
-1
No files matched your search
@@ -1,3 +1,5 @@
|
|||||||
|
### V2.3.0
|
||||||
|
* additional batch method
|
||||||
### V2.2.0
|
### V2.2.0
|
||||||
* add batch execution
|
* add batch execution
|
||||||
### V2.1.1
|
### V2.1.1
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ func (c scriptController) Execute(req domain.ExecuteRequest) *domain.ScriptResp
|
|||||||
return service.Script.Execute(req)
|
return service.Script.Execute(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c scriptController) BatchExecute(req []domain.ExecuteByIdRequest) []domain.ScriptResp {
|
||||||
|
return service.Script.BatchExecute(req)
|
||||||
|
}
|
||||||
|
|
||||||
func (c scriptController) BatchExecuteById(req domain.BatchExecuteByIdsRequest) []domain.ScriptResp {
|
func (c scriptController) BatchExecuteById(req domain.BatchExecuteByIdsRequest) []domain.ScriptResp {
|
||||||
return service.Script.BatchExecuteById(req)
|
return service.Script.BatchExecuteById(req)
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
type ScriptHandlers struct {
|
type ScriptHandlers struct {
|
||||||
ExecuteById func(request domain.ExecuteByIdRequest) (*domain.ScriptResp, error) `method:"execute_by_id" group:"script"`
|
ExecuteById func(request domain.ExecuteByIdRequest) (*domain.ScriptResp, error) `method:"execute_by_id" group:"script"`
|
||||||
Execute func(request domain.ExecuteRequest) *domain.ScriptResp `method:"execute" group:"script"`
|
Execute func(request domain.ExecuteRequest) *domain.ScriptResp `method:"execute" group:"script"`
|
||||||
|
BatchExecute func(request []domain.ExecuteByIdRequest) []domain.ScriptResp `method:"batch_execute" group:"script"`
|
||||||
BatchExecuteByIds func(request domain.BatchExecuteByIdsRequest) []domain.ScriptResp `method:"batch_execute_by_ids" group:"script"`
|
BatchExecuteByIds func(request domain.BatchExecuteByIdsRequest) []domain.ScriptResp `method:"batch_execute_by_ids" group:"script"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -15,6 +16,7 @@ func GetTaskHandler() *ScriptHandlers {
|
|||||||
return &ScriptHandlers{
|
return &ScriptHandlers{
|
||||||
ExecuteById: controller.Script.ExecuteById,
|
ExecuteById: controller.Script.ExecuteById,
|
||||||
Execute: controller.Script.Execute,
|
Execute: controller.Script.Execute,
|
||||||
|
BatchExecute: controller.Script.BatchExecute,
|
||||||
BatchExecuteByIds: controller.Script.BatchExecuteById,
|
BatchExecuteByIds: controller.Script.BatchExecuteById,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,25 @@ func (s *scriptService) ExecuteById(req domain.ExecuteByIdRequest) (*domain.Scri
|
|||||||
return s.executeScript(scr, req.Arg), nil
|
return s.executeScript(scr, req.Arg), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *scriptService) BatchExecute(req []domain.ExecuteByIdRequest) []domain.ScriptResp {
|
||||||
|
wg := sync.WaitGroup{}
|
||||||
|
store := s.store.Load().(map[string]script.Script)
|
||||||
|
response := make([]domain.ScriptResp, len(req))
|
||||||
|
for i := range req {
|
||||||
|
wg.Add(1)
|
||||||
|
go func(i int) {
|
||||||
|
defer wg.Done()
|
||||||
|
if store[req[i].Id] == nil {
|
||||||
|
response[i] = *s.respError(errors.Errorf("not defined script for id %s", req[i].Id), domain.ErrorCompile)
|
||||||
|
} else {
|
||||||
|
response[i] = *s.executeScript(store[req[i].Id], req[i].Arg)
|
||||||
|
}
|
||||||
|
}(i)
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
func (s *scriptService) BatchExecuteById(req domain.BatchExecuteByIdsRequest) []domain.ScriptResp {
|
func (s *scriptService) BatchExecuteById(req domain.BatchExecuteByIdsRequest) []domain.ScriptResp {
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
store := s.store.Load().(map[string]script.Script)
|
store := s.store.Load().(map[string]script.Script)
|
||||||
|
|||||||
Reference in new issue
Block a user