forked from longtao.wu/droboticflow
90 lines
4.0 KiB
Go
90 lines
4.0 KiB
Go
package domain
|
|
|
|
import (
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/bson/bsonrw"
|
|
)
|
|
|
|
// ProcessingJob is a private durable outbox embedded in the authoritative
|
|
// HumanItem CAS. Creating a submission and queuing it are one database write.
|
|
type AnnotationProcessingJob struct {
|
|
ID string `bson:"id" json:"id"`
|
|
Kind string `bson:"kind" json:"kind"`
|
|
TaskID string `bson:"taskId" json:"taskId"`
|
|
ActorID string `bson:"actorId" json:"actorId"`
|
|
Input map[string]any `bson:"input,omitempty" json:"-"`
|
|
SourceFingerprint string `bson:"sourceFingerprint,omitempty" json:"-"`
|
|
SourceIndex bool `bson:"sourceIndex,omitempty" json:"-"`
|
|
Revision int `bson:"revision,omitempty" json:"revision,omitempty"`
|
|
Status string `bson:"status" json:"status"`
|
|
Owner string `bson:"owner,omitempty" json:"-"`
|
|
LeaseUntil string `bson:"leaseUntil,omitempty" json:"-"`
|
|
NextAttemptAt string `bson:"nextAttemptAt,omitempty" json:"-"`
|
|
// Set while a revision waits for source validation; absent on other jobs.
|
|
ValidationSince string `bson:"validationSince,omitempty" json:"-"`
|
|
ValidationWaits int `bson:"validationWaits,omitempty" json:"-"`
|
|
Attempt int `bson:"attempt" json:"attempt"`
|
|
Stage string `bson:"stage,omitempty" json:"stage,omitempty"`
|
|
CompletedSlices int `bson:"completedSlices" json:"completedSlices"`
|
|
TotalSlices int `bson:"totalSlices" json:"totalSlices"`
|
|
Error string `bson:"error,omitempty" json:"error,omitempty"`
|
|
CreatedAt string `bson:"createdAt" json:"createdAt"`
|
|
UpdatedAt string `bson:"updatedAt" json:"updatedAt"`
|
|
}
|
|
|
|
// HasActiveAnnotationJob identifies the durable job responsible for this request.
|
|
// Its lease may already have expired: the processor queue must reclaim that job,
|
|
// rather than letting a legacy timeout mark its business workflow as failed.
|
|
func HasActiveAnnotationJob(item *HumanItemRecord, kind, requestID string) bool {
|
|
if item == nil || item.ProcessingJob == nil || requestID == "" {
|
|
return false
|
|
}
|
|
job := item.ProcessingJob
|
|
return job.Kind == kind && job.ID == requestID && (job.Status == "queued" || job.Status == "running")
|
|
}
|
|
|
|
func (j *AnnotationProcessingJob) UnmarshalBSON(data []byte) error {
|
|
type plain AnnotationProcessingJob
|
|
decoder, e := bson.NewDecoder(bsonrw.NewBSONDocumentReader(data))
|
|
if e != nil {
|
|
return e
|
|
}
|
|
decoder.DefaultDocumentM()
|
|
var out plain
|
|
if e = decoder.Decode(&out); e != nil {
|
|
return e
|
|
}
|
|
*j = AnnotationProcessingJob(out)
|
|
return nil
|
|
}
|
|
|
|
type AnnotationTimelineIndex struct {
|
|
ID string `bson:"id"`
|
|
OrganizationID string `bson:"organizationId"`
|
|
ProjectID string `bson:"projectId"`
|
|
WorkflowID string `bson:"workflowId"`
|
|
RunID string `bson:"runId"`
|
|
Body []byte `bson:"body"`
|
|
SHA256 string `bson:"sha256"`
|
|
CreatedAt string `bson:"createdAt"`
|
|
}
|
|
|
|
type AnnotationIndexJob struct {
|
|
RevalidateSource bool `bson:"revalidateSource,omitempty"`
|
|
SupersededSourceFingerprint string `bson:"supersededSourceFingerprint,omitempty"`
|
|
SourceFingerprint string `bson:"sourceFingerprint,omitempty"`
|
|
ID string `bson:"id"`
|
|
TaskID string `bson:"taskId,omitempty"`
|
|
OrganizationID string `bson:"organizationId"`
|
|
ProjectID string `bson:"projectId"`
|
|
WorkflowID string `bson:"workflowId"`
|
|
RunID string `bson:"runId"`
|
|
Status string `bson:"status"`
|
|
Owner string `bson:"owner,omitempty"`
|
|
LeaseUntil string `bson:"leaseUntil,omitempty"`
|
|
Attempt int `bson:"attempt"`
|
|
NextAttemptAt string `bson:"nextAttemptAt"`
|
|
Error string `bson:"error,omitempty"`
|
|
CreatedAt string `bson:"createdAt"`
|
|
}
|