fasten-onprem/backend/pkg/models/background_job_sync.go

35 lines
946 B
Go
Raw Normal View History

2023-10-08 17:29:26 -06:00
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(),
2023-10-08 17:29:26 -06:00
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"`
2023-10-08 17:29:26 -06:00
CheckpointData map[string]interface{} `json:"checkpoint_data,omitempty"`
ErrorData map[string]interface{} `json:"error_data,omitempty"`
}