forked from Yara724/api
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
|
|
import { Schema as MongoSchema } from "mongoose";
|
|
import { AiResult } from "./ai-result";
|
|
|
|
@Schema({ collection: "ai-damage-jobs", timestamps: true, versionKey: false })
|
|
export class AiJob {
|
|
@Prop({ required: true }) claimId: string;
|
|
@Prop({ required: true }) imageKey: string;
|
|
@Prop({ required: true }) path: string;
|
|
@Prop() fileName?: string;
|
|
@Prop({
|
|
default: "queued",
|
|
enum: ["queued", "processing", "completed", "failed"],
|
|
})
|
|
status: string;
|
|
@Prop({ default: 0 }) attempts: number;
|
|
@Prop({ default: () => new Date() }) nextAttemptAt: Date;
|
|
@Prop() leaseUntil?: Date;
|
|
@Prop() leaseToken?: string;
|
|
@Prop() completedAt?: Date;
|
|
@Prop() error?: string;
|
|
@Prop() errorCode?: string;
|
|
@Prop() errorRequestId?: string;
|
|
@Prop({ type: MongoSchema.Types.Mixed }) result?: AiResult;
|
|
}
|
|
export const AiJobSchema = SchemaFactory.createForClass(AiJob);
|
|
AiJobSchema.index({ claimId: 1, imageKey: 1 }, { unique: true });
|
|
AiJobSchema.index({ status: 1, nextAttemptAt: 1, leaseUntil: 1 });
|