-
Notifications
You must be signed in to change notification settings - Fork 0
/
executor_invoker.go
41 lines (33 loc) · 985 Bytes
/
executor_invoker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package serversupport
import (
"encoding/json"
"github.com/danenmao/pterergate-dtf/dtf/errordef"
"github.com/danenmao/pterergate-dtf/dtf/taskmodel"
)
type ExecutorInvoker struct {
*InvokerBase
}
func NewExecutorInvoker(serverHost string, serverPort uint16, user string) *ExecutorInvoker {
return &ExecutorInvoker{
InvokerBase: NewInvokerBase(serverHost, serverPort, ExecutorServerURI, user),
}
}
// return an invoker function
// for scheduler to invoke the executor
// executor invoker, send subtasks to the executor
func (e *ExecutorInvoker) GetInvoker() taskmodel.ExecutorInvoker {
return func(subtaskBody []taskmodel.SubtaskBody) error {
return e.invoke(subtaskBody)
}
}
func (e *ExecutorInvoker) invoke(subtasks []taskmodel.SubtaskBody) error {
body := ExecutorRequestBody{
Subtasks: subtasks,
}
data, err := json.Marshal(body)
if err != nil {
return errordef.ErrOperationFailed
}
_, err = e.client.Post(e.url, e.UserName, string(data))
return err
}