feat: expose image search snapshot in task payload (#278)

This commit is contained in:
QiuSW
2026-09-14 16:49:35 +08:00
parent 35b69fc25a
commit 66ab36c88c
2 changed files with 10 additions and 0 deletions
+1
View File
@@ -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"`
+9
View File
@@ -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