func (t *Task) update(task *TaskMessage) error {
	isExists := false
	for _, taskMessage := range t.TaskMessages {
		if taskMessage.TaskLogId == task.TaskLogId {
			isExists = true
			taskMessage.Path = task.Path
			taskMessage.Status = task.Status
			taskMessage.IsSuccess = task.IsSuccess
			taskMessage.GitX = task.GitX
			taskMessage.PreCommandX = task.PreCommandX
			taskMessage.PostCommandX = task.PostCommandX
			taskMessage.Result = task.Result
			taskMessage.CommitId = task.CommitId
		}
	}
	if !isExists {
		return errors.New("The task not exists")
	}
	return nil
}
update by taskLogId
package message
import (
	"sync"
	"errors"
	"bzppx-agent-codepub/utils"
)
const Task_Status_Default = 0  
const Task_Status_Starting = 1  
const Task_Status_End = 2  
const Task_Failed = 0  
const Task_Success = 1  
func NewTask() *Task {
	return &Task{
		lock: sync.Mutex{},
		TaskMessages: []*TaskMessage{},
	}
}
type Task struct {
	lock sync.Mutex
	TaskMessages []*TaskMessage
}
type TaskMessage struct {
	TaskLogId string
	Path string
	Status int
	IsSuccess int
	GitX utils.GitXParams
	PreCommandX utils.CommandXParams
	PostCommandX utils.CommandXParams
	Result string
	CommitId string
}
func (t *Task) Add(taskLogId string, path string, gitX utils.GitXParams, preCommandX utils.CommandXParams, postCommandX utils.CommandXParams) error {
	t.lock.Lock()
	defer t.lock.Unlock()
	return t.add(taskLogId, path, gitX, preCommandX, postCommandX)
}
func (t *Task) add(taskLogId string, path string, gitX utils.GitXParams, preCommandX utils.CommandXParams, postCommandX utils.CommandXParams) error {
	taskMessages := t.TaskMessages
	for _, taskMessage := range taskMessages {
		if taskMessage.TaskLogId == taskLogId {
			return errors.New("The task already exists")
		}
	}
	taskMsg := &TaskMessage{
		TaskLogId: taskLogId,
		Path: path,
		Status: Task_Status_Default,
		IsSuccess: Task_Failed,
		GitX: gitX,
		PreCommandX: preCommandX,
		PostCommandX: postCommandX,
		Result: "",
		CommitId: "",
	}
	t.TaskMessages = append(t.TaskMessages, taskMsg)
	return nil
}
func (t *Task) Delete(taskLogId string) error {
	t.lock.Lock()
	defer t.lock.Unlock()
	return t.del(taskLogId)
}
func (t *Task) del(taskLogId string) error {
	taskMessages := []*TaskMessage{}
	for _, taskMessage := range t.TaskMessages {
		if taskMessage.TaskLogId == taskLogId {
			continue
		}
		taskMessages = append(taskMessages, taskMessage)
	}
	t.TaskMessages = taskMessages
	return nil
}
func (t *Task) Start(taskLogId string) (err error) {
	t.lock.Lock()
	defer t.lock.Unlock()
	taskMessage, err := t.GetTask(taskLogId)
	if err != nil {
		return
	}
	newTaskMessage := &TaskMessage{
		TaskLogId: taskLogId,
		Path: taskMessage.Path,
		Status: Task_Status_Starting,
		IsSuccess: taskMessage.IsSuccess,
		GitX: taskMessage.GitX,
		PreCommandX: taskMessage.PreCommandX,
		PostCommandX: taskMessage.PostCommandX,
		Result: taskMessage.Result,
		CommitId: taskMessage.CommitId,
	}
	return t.update(newTaskMessage)
}
func (t *Task) End(taskLogId string, isSuccess int, result string, commitId string) (err error) {
	t.lock.Lock()
	defer t.lock.Unlock()
	taskMessage, err := t.GetTask(taskLogId)
	if err != nil {
		return
	}
	newTaskMessage := &TaskMessage{
		TaskLogId: taskLogId,
		Path: taskMessage.Path,
		Status:Task_Status_End,
		IsSuccess: isSuccess,
		GitX: taskMessage.GitX,
		PreCommandX: taskMessage.PreCommandX,
		PostCommandX: taskMessage.PostCommandX,
		Result: result,
		CommitId: commitId,
	}
	return t.update(newTaskMessage)
}
func (t *Task) GetTask(taskLogId string) (*TaskMessage, error)  {
	taskMessages := t.TaskMessages
	for _, taskMessage := range taskMessages {
		if taskMessage.TaskLogId == taskLogId {
			return taskMessage, nil
		}
	}
	return nil, errors.New("The task not exists")
}