forked from pinks/eris
1
0
Fork 0
eris/db/jobStore.ts

50 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-09-10 18:56:17 +00:00
import { GrammyTypes, IKV } from "../deps.ts";
2023-09-13 09:50:22 +00:00
import { SdTxt2ImgInfo } from "../common/sdApi.ts";
import { PngInfo } from "../common/parsePngInfo.ts";
2023-09-10 18:56:17 +00:00
import { db } from "./db.ts";
export interface JobSchema {
2023-09-12 01:57:44 +00:00
task:
| {
type: "txt2img";
params: Partial<PngInfo>;
}
| {
type: "img2img";
params: Partial<PngInfo>;
fileId: string;
};
2023-09-12 01:57:44 +00:00
from: GrammyTypes.User;
chat: GrammyTypes.Chat;
requestMessageId: number;
2023-09-10 18:56:17 +00:00
status:
| {
type: "waiting";
message?: GrammyTypes.Message.TextMessage;
2023-09-14 01:23:55 +00:00
lastErrorDate?: Date;
}
| {
type: "processing";
progress: number;
worker: string;
updatedDate: Date;
message?: GrammyTypes.Message.TextMessage;
}
| {
type: "done";
info?: SdTxt2ImgInfo;
startDate?: Date;
endDate?: Date;
};
2023-09-10 18:56:17 +00:00
}
2023-09-17 23:01:09 +00:00
type JobIndices = {
"status.type": JobSchema["status"]["type"];
};
export const jobStore = new IKV.Store<JobSchema, JobIndices>(db, "job", {
indices: {
"status.type": { getValue: (job) => job.status.type },
},
2023-09-10 18:56:17 +00:00
});