fix: preserve attachment pipeline invariants
This commit is contained in:
@@ -361,7 +361,7 @@ func (s *Store) CompleteAttachmentJob(
|
||||
lease model.AttachmentJobLease,
|
||||
variants []model.Variant,
|
||||
) (model.JobMutationResult, error) {
|
||||
if !validCompletedVariants(variants) {
|
||||
if !validCompletedVariants(variants, lease.Job.PipelineVersion) {
|
||||
return "", model.ErrInvalidInput
|
||||
}
|
||||
tx, err := s.pool.BeginTx(ctx, pgx.TxOptions{})
|
||||
@@ -423,20 +423,23 @@ func (s *Store) CompleteAttachmentJob(
|
||||
return model.JobMutationApplied, nil
|
||||
}
|
||||
|
||||
func validCompletedVariants(variants []model.Variant) bool {
|
||||
seen := make(map[string]struct{}, len(variants))
|
||||
for _, variant := range variants {
|
||||
if variant.Name == "" || variant.ObjectKey == "" {
|
||||
return false
|
||||
}
|
||||
if _, duplicate := seen[variant.Name]; duplicate {
|
||||
return false
|
||||
}
|
||||
seen[variant.Name] = struct{}{}
|
||||
func validCompletedVariants(variants []model.Variant, pipelineVersion int) bool {
|
||||
if len(variants) != 4 || pipelineVersion < 1 {
|
||||
return false
|
||||
}
|
||||
_, hasOriginal := seen["original"]
|
||||
_, hasThumbnail := seen["thumbnail"]
|
||||
return hasOriginal && hasThumbnail
|
||||
required := map[string]struct{}{
|
||||
"original": {}, "thumbnail": {}, "crop": {}, "optimized": {},
|
||||
}
|
||||
for _, variant := range variants {
|
||||
if variant.ObjectKey == "" || variant.PipelineVersion != pipelineVersion {
|
||||
return false
|
||||
}
|
||||
if _, exists := required[variant.Name]; !exists {
|
||||
return false
|
||||
}
|
||||
delete(required, variant.Name)
|
||||
}
|
||||
return len(required) == 0
|
||||
}
|
||||
|
||||
func (s *Store) RetryAttachmentJob(
|
||||
|
||||
Reference in New Issue
Block a user