Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[fix] use string and []byte to store resource #49

Merged
merged 1 commit into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 , 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
}
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