Skip to content

Commit

Permalink
[fix] use string and []byte to store resource
Browse files Browse the repository at this point in the history
  • Loading branch information
robotLJW committed Dec 27, 2021
1 parent 0bb606b commit 9967d71
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
4 changes: 3 additions & 1 deletion discovery/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

package discovery

import "fmt"
import (
"fmt"
)

const (
MS_UP string = "UP"
Expand Down
24 changes: 15 additions & 9 deletions sync/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package sync

import (
"encoding/json"
"time"

"github.com/gofrs/uuid"
Expand All @@ -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 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
}
16 changes: 8 additions & 8 deletions sync/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9967d71

Please # to comment.