forked from longtao.wu/droboticflow
43 lines
1.5 KiB
Go
43 lines
1.5 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"droboticflow/internal/domain"
|
|
"droboticflow/internal/store"
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
var errSourceValidationPending = errors.New("source validation pending")
|
|
|
|
// Waiting for a cold source must not occupy a revision worker, count as a
|
|
// crash/retry, or mark the user's slice workflow failed. Historical timeline
|
|
// jobs may already be completed, so source validation has a separate durable ID.
|
|
func (s *server) requirePreparedAnnotationSource(ctx context.Context, t domain.AnnotationTaskRecord, fingerprint string, explicitRetry bool) error {
|
|
db, ok := s.store.(store.AnnotationProcessingStore)
|
|
if !ok {
|
|
return fmt.Errorf("source index store unavailable")
|
|
}
|
|
record, e := db.GetAnnotationTimelineIndex(ctx, sourceCertificateID(t.OrganizationID, fingerprint))
|
|
if e != nil {
|
|
return e
|
|
}
|
|
if cert, e := decodeSourceCertificate(record, fingerprint); e == nil && cert != nil {
|
|
return nil
|
|
}
|
|
s.annotationSourceCertificates.mu.Lock()
|
|
delete(s.annotationSourceCertificates.entries, fingerprint)
|
|
s.annotationSourceCertificates.mu.Unlock()
|
|
if e = db.EnqueueAnnotationSourceIndex(ctx, t, fingerprint, explicitRetry); e != nil {
|
|
return e
|
|
}
|
|
j, e := db.GetAnnotationIndexJob(ctx, store.AnnotationSourceJobID(t.OrganizationID, fingerprint))
|
|
if e != nil {
|
|
return e
|
|
}
|
|
if j != nil && j.Status == "failed" {
|
|
return fmt.Errorf("源文件预校验失败,编辑内容已保留;请修复源数据或重试:%s", j.Error)
|
|
}
|
|
return errSourceValidationPending
|
|
}
|