in agent/taskengine/basetask.go [75:145]
func NewTask(taskInfo models.RunTaskInfo, scheduleLocation *time.Location, onFinish FinishCallback, onReportError ReportErrorCallback) (*Task, error) {
timeout, err := strconv.Atoi(taskInfo.TimeOut)
if err != nil {
timeout = 3600
}
var processor models.TaskProcessor
var isHostProcessor bool
if taskInfo.ContainerId != "" || taskInfo.ContainerName != "" {
annotation := map[string]string{
"containerId": taskInfo.ContainerId,
"containerName": taskInfo.ContainerName,
}
processor, err = commander.NewCommanderProcessor(taskInfo, timeout, annotation, commandermanager.ContainerCommanderName)
if err != nil {
return nil, err
}
} else {
// Check if launcher it's a commander
if isCommander, commanderName := checkLauncherCommander(taskInfo.Launcher, taskInfo.TaskId); isCommander {
// Put all param into annotation
annotation := map[string]string{
LAUNCHER_CMDLINE: taskInfo.Launcher,
}
processor, err = commander.NewCommanderProcessor(taskInfo, timeout, annotation, commanderName)
if err != nil {
return nil, err
}
} else {
processor = &host.HostProcessor{
TaskId: taskInfo.TaskId,
InvokeVersion: taskInfo.InvokeVersion,
CommandType: taskInfo.CommandType,
Repeat: taskInfo.Repeat,
Timeout: timeout,
CommandName: taskInfo.CommandName,
WorkingDirectory: taskInfo.WorkingDir,
Username: taskInfo.Username,
WindowsUserPassword: taskInfo.Password,
TerminationMode: taskInfo.TerminationMode,
Launcher: taskInfo.Launcher,
}
isHostProcessor = true
}
}
task := &Task{
taskInfo: taskInfo,
scheduleLocation: scheduleLocation,
onFinish: onFinish,
onReportError: onReportError,
processer: processor,
canceled: false,
droped: 0,
disableOutputRingbuffer: flagging.IsTaskOutputRingbufferDisabled(),
}
if task.disableOutputRingbuffer {
task.outputBuf = &outputbuffer.LegacyOutputBuffer{}
} else {
task.outputBuf = &outputbuffer.OutputBuffer{}
}
if isHostProcessor && langutil.NeedTransformEncoding() {
task.outputBuf.SetTransformer(func(s []byte) (d []byte) {
d, _ = langutil.GbkToUtf8(s)
return
})
}
return task, nil
}