feat: expose image search snapshot in task payload (#278)
This commit is contained in:
@@ -189,6 +189,7 @@ type CollectionTask struct {
|
||||
URLSnapshot string `json:"urlSnapshot" gorm:"type:text;not null"`
|
||||
GoodsIDSnapshot string `json:"goodsIdSnapshot" gorm:"size:32;not null;index"`
|
||||
RuleSnapshot string `json:"ruleSnapshot" gorm:"type:text;not null"`
|
||||
ImageSearchSnapshot *string `json:"imageSearch,omitempty" gorm:"type:text"`
|
||||
AttemptNumber int `json:"attemptNumber" gorm:"not null;default:1;check:ck_collection_task_attempt_number,attempt_number >= 1"`
|
||||
LeaseExpiresAt *time.Time `json:"leaseExpiresAt" gorm:"index"`
|
||||
LeaseVersion uint64 `json:"leaseVersion" gorm:"not null;default:0"`
|
||||
|
||||
@@ -60,6 +60,7 @@ type TaskPayload struct {
|
||||
ReplacementOriginType string `json:"replacementOriginType,omitempty"`
|
||||
RuleID uint64 `json:"ruleId"`
|
||||
RuleSnapshot json.RawMessage `json:"ruleSnapshot"`
|
||||
ImageSearch json.RawMessage `json:"imageSearch,omitempty"`
|
||||
TimeoutSeconds int `json:"timeoutSeconds"`
|
||||
LeaseExpiresAt *time.Time `json:"leaseExpiresAt,omitempty"`
|
||||
LeaseVersion uint64 `json:"leaseVersion"`
|
||||
@@ -286,6 +287,13 @@ func (service *Service) payload(record models.CollectionTask, replayed bool) (Ta
|
||||
if !json.Valid(rule) {
|
||||
return TaskPayload{}, internalError(errors.New("stored rule snapshot is invalid JSON"))
|
||||
}
|
||||
var imageSearch json.RawMessage
|
||||
if record.ImageSearchSnapshot != nil && *record.ImageSearchSnapshot != "" {
|
||||
imageSearch = json.RawMessage(*record.ImageSearchSnapshot)
|
||||
if !json.Valid(imageSearch) {
|
||||
return TaskPayload{}, internalError(errors.New("stored image search snapshot is invalid JSON"))
|
||||
}
|
||||
}
|
||||
timeout := service.TaskTimeout
|
||||
if timeout <= 0 {
|
||||
timeout = DefaultTaskTimeout
|
||||
@@ -295,6 +303,7 @@ func (service *Service) payload(record models.CollectionTask, replayed bool) (Ta
|
||||
URLSnapshot: record.URLSnapshot, GoodsIDSnapshot: record.GoodsIDSnapshot,
|
||||
Source: record.Source, ReplacementOriginType: pointerValue(record.ReplacementOriginType),
|
||||
RuleID: record.RuleID, RuleSnapshot: rule, TimeoutSeconds: timeout,
|
||||
ImageSearch: imageSearch,
|
||||
LeaseExpiresAt: record.LeaseExpiresAt, LeaseVersion: record.LeaseVersion,
|
||||
Status: record.Status, Replayed: replayed,
|
||||
}, nil
|
||||
|
||||
Reference in New Issue
Block a user