func buildAgentTaskComplete(log log.T, res contracts.DocumentResult, instanceId string) (result []byte, err error) {
	uuid.SwitchFormat(uuid.CleanHyphen)
	messageId := uuid.NewV4()
	pluginId := res.LastPlugin
	var taskCompletePayload interface{}
	var messageType string

	// For SessionManager plugins, there is only one plugin in a document.
	// Send AgentTaskComplete when we get the plugin level result, and ignore this document level result.
	// For instance reboot scenarios, it only has document level result with "Failed" status, this result can't be ignored.
	if pluginId == "" && res.Status != contracts.ResultStatusFailed {
		return nil, nil
	}

	messageType = mgsContracts.TaskCompleteMessage
	taskCompletePayload = formatAgentTaskCompletePayload(log, pluginId, res.PluginResults, res.MessageID, instanceId, messageType)
	replyBytes, err := json.Marshal(taskCompletePayload)
	if err != nil {
		// should not happen
		return nil, fmt.Errorf("cannot marshal AgentReply payload to json string: %s, err: %s", taskCompletePayload, err)
	}
	payload := string(replyBytes)
	log.Info("Sending reply ", jsonutil.Indent(payload))

	agentMessage := &mgsContracts.AgentMessage{
		MessageType:    messageType,
		SchemaVersion:  1,
		CreatedDate:    uint64(time.Now().UnixNano() / 1000000),
		SequenceNumber: 0,
		Flags:          0,
		MessageId:      messageId,
		Payload:        replyBytes,
	}

	return agentMessage.Serialize(log)
}
// buildAgentTaskComplete builds AgentTaskComplete message.
buildAgentTaskComplete builds AgentTaskComplete message.
// buildAgentTaskComplete builds AgentTaskComplete message .
func buildAgentTaskComplete(log log.T, res contracts.DocumentResult, instanceId string) (result []byte, err error) {
	uuid.SwitchFormat(uuid.CleanHyphen)
	messageId := uuid.NewV4()
	pluginId := res.LastPlugin
	var taskCompletePayload interface{}
	var messageType string
	if pluginId == "" && res.Status != contracts.ResultStatusFailed {
		return nil, nil
	}
	messageType = mgsContracts.TaskCompleteMessage
	taskCompletePayload = formatAgentTaskCompletePayload(log, pluginId, res.PluginResults, res.MessageID, instanceId, messageType)
	replyBytes, err := json.Marshal(taskCompletePayload)
	if err != nil {
		return nil, fmt.Errorf("cannot marshal AgentReply payload to json string: %s, err: %s", taskCompletePayload, err)
	}
	payload := string(replyBytes)
	log.Info("Sending reply ", jsonutil.Indent(payload))
	agentMessage := &mgsContracts.AgentMessage{
		MessageType:    messageType,
		SchemaVersion:  1,
		CreatedDate:    uint64(time.Now().UnixNano() / 1000000),
		SequenceNumber: 0,
		Flags:          0,
		MessageId:      messageId,
		Payload:        replyBytes,
	}
	return agentMessage.Serialize(log)
}
func buildAgentTaskComplete ( log log . T , res contracts . DocumentResult , instanceId string ) ( result [ ] byte , err error ) { uuid . SwitchFormat ( uuid . CleanHyphen ) messageId := uuid . NewV4 ( ) pluginId := res . LastPlugin var taskCompletePayload interface { } var messageType string if pluginId == " " && res . Status != contracts . ResultStatusFailed { return nil , nil } messageType = mgsContracts . TaskCompleteMessage taskCompletePayload = formatAgentTaskCompletePayload ( log , pluginId , res . PluginResults , res . MessageID , instanceId , messageType ) replyBytes , err := json . Marshal ( taskCompletePayload ) if err != nil { return nil , fmt . Errorf ( " " , taskCompletePayload , err ) } payload := string ( replyBytes ) log . Info ( " " , jsonutil . Indent ( payload ) ) agentMessage := & mgsContracts . AgentMessage { MessageType : messageType , SchemaVersion : 1 , CreatedDate : uint64 ( time . Now ( ) . UnixNano ( ) / 1000000 ) , SequenceNumber : 0 , Flags : 0 , MessageId : messageId , Payload : replyBytes , } return agentMessage . Serialize ( log ) }
buildAgentTaskComplete builds AgentTaskComplete message.
buildAgentTaskComplete builds AgentTaskComplete message .
// For SessionManager plugins, there is only one plugin in a document. // Send AgentTaskComplete when we get the plugin level result, and ignore this document level result. // For instance reboot scenarios, it only has document level result with "Failed" status, this result can't be ignored. // should not happen