additional batch method
This commit is contained in:
1 parent
e52217a99b
commit
983474cdb7
5 files changed
+28
-1
No files matched your search
@@ -1,3 +1,5 @@
|
||||
### V2.3.0
|
||||
* additional batch method
|
||||
### V2.2.0
|
||||
* add batch execution
|
||||
### V2.1.1
|
||||
|
||||
@@ -17,6 +17,10 @@ func (c scriptController) Execute(req domain.ExecuteRequest) *domain.ScriptResp
|
||||
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 {
|
||||
return service.Script.BatchExecuteById(req)
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
type ScriptHandlers struct {
|
||||
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"`
|
||||
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"`
|
||||
}
|
||||
|
||||
@@ -15,6 +16,7 @@ func GetTaskHandler() *ScriptHandlers {
|
||||
return &ScriptHandlers{
|
||||
ExecuteById: controller.Script.ExecuteById,
|
||||
Execute: controller.Script.Execute,
|
||||
BatchExecute: controller.Script.BatchExecute,
|
||||
BatchExecuteByIds: controller.Script.BatchExecuteById,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,25 @@ func (s *scriptService) ExecuteById(req domain.ExecuteByIdRequest) (*domain.Scri
|
||||
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 {
|
||||
wg := sync.WaitGroup{}
|
||||
store := s.store.Load().(map[string]script.Script)
|
||||
|
||||
Reference in new issue
Block a user