35 lines
946 B
Go
35 lines
946 B
Go
package models
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/fastenhealth/fasten-onprem/backend/pkg"
|
|
"github.com/google/uuid"
|
|
"time"
|
|
)
|
|
|
|
func NewSyncBackgroundJob(source SourceCredential) *BackgroundJob {
|
|
now := time.Now()
|
|
data := BackgroundJobSyncData{
|
|
SourceID: source.ID,
|
|
BrandID: source.BrandID.String(),
|
|
CheckpointData: nil,
|
|
ErrorData: nil,
|
|
}
|
|
|
|
dataJson, _ := json.Marshal(data)
|
|
|
|
return &BackgroundJob{
|
|
JobType: pkg.BackgroundJobTypeSync,
|
|
JobStatus: pkg.BackgroundJobStatusLocked, //we lock the job immediately so that it doesn't get picked up by another worker
|
|
LockedTime: &now,
|
|
Data: dataJson,
|
|
}
|
|
}
|
|
|
|
type BackgroundJobSyncData struct {
|
|
SourceID uuid.UUID `json:"source_id"`
|
|
BrandID string `json:"brand_id"`
|
|
CheckpointData map[string]interface{} `json:"checkpoint_data,omitempty"`
|
|
ErrorData map[string]interface{} `json:"error_data,omitempty"`
|
|
}
|