From 9af3f364c4efc2a55d6c96da03b045b8514b0e48 Mon Sep 17 00:00:00 2001 From: robotljw <790504160@qq.com> Date: Mon, 27 Dec 2021 19:40:02 +0800 Subject: [PATCH] [fix] use string and []byte to store resource --- discovery/types.go | 4 +++- sync/task.go | 24 +++++++++++++++--------- sync/types.go | 16 ++++++++-------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/discovery/types.go b/discovery/types.go index cf25b40..7c6c54e 100644 --- a/discovery/types.go +++ b/discovery/types.go @@ -17,7 +17,9 @@ package discovery -import "fmt" +import ( + "fmt" +) const ( MS_UP string = "UP" diff --git a/sync/task.go b/sync/task.go index 35f5e70..c3c7dce 100644 --- a/sync/task.go +++ b/sync/task.go @@ -18,6 +18,7 @@ package sync import ( + "encoding/json" "time" "github.com/gofrs/uuid" @@ -28,19 +29,24 @@ const ( DoneStatus = "done" ) -// NewTask return task with action and datatype -func NewTask(domain, project, action, dataType string) (*Task, error) { +// NewTask return task with domain, project , action , resourceType and resource +func NewTask(domain, project, action, resourceType string, resource interface{}) (*Task, error) { taskId, err := uuid.NewV4() if err != nil { return nil, err } + resourceValue, err := json.Marshal(resource) + if err != nil { + return nil, err + } return &Task{ - TaskID: taskId.String(), - Action: action, - DataType: dataType, - Domain: domain, - Project: project, - Timestamp: time.Now().UnixNano(), - Status: PendingStatus, + ID: taskId.String(), + Domain: domain, + Project: project, + ResourceType: resourceType, + Resource: resourceValue, + Action: action, + Timestamp: time.Now().UnixNano(), + Status: PendingStatus, }, nil } diff --git a/sync/types.go b/sync/types.go index 40bac6d..305d61c 100644 --- a/sync/types.go +++ b/sync/types.go @@ -25,14 +25,14 @@ const ( // Task is db struct to store sync task type Task struct { - TaskID string `json:"task_id" bson:"task_id"` - Action string `json:"action" bson:"action"` - DataType string `json:"data_type" bson:"data_type"` - Domain string `json:"domain" bson:"domain"` - Project string `json:"project" bson:"project"` - Data interface{} `json:"data" bson:"data"` - Timestamp int64 `json:"timestamp" bson:"timestamp"` - Status string `json:"status" bson:"status"` + ID string `json:"id" bson:"id"` + Domain string `json:"domain" bson:"domain"` + Project string `json:"project" bson:"project"` + ResourceType string `json:"resource_type" bson:"resource_type"` + Resource []byte `json:"resource" bson:"resource"` + Action string `json:"action" bson:"action"` + Timestamp int64 `json:"timestamp" bson:"timestamp"` + Status string `json:"status" bson:"status"` } // Tombstone is db struct to store the deleted resource information