Files
i-tools/app/lib/testcase-backend/store.ts
yfan 3d175d75af
Some checks failed
Build and Push Docker Image / build (push) Has been cancelled
Sync to CNB / sync (push) Has been cancelled
Delete old workflow runs / del_runs (push) Has been cancelled
Upstream Sync / Sync latest commits from upstream repo (push) Has been cancelled
first commit
2026-01-30 16:57:44 +08:00

53 lines
1.5 KiB
TypeScript

import type { Task, CreateTaskParams } from "./types";
const tasks = new Map<string, Task>();
export function getTask(taskId: string): Task | undefined {
return tasks.get(taskId);
}
export function setTask(taskId: string, task: Task): void {
tasks.set(taskId, task);
}
export function createTask(taskId: string, params: CreateTaskParams): Task {
const task: Task = {
id: taskId,
status: "pending",
title: params.title.trim(),
englishName: params.englishName.trim().toLowerCase(),
description: params.description.trim(),
standardCode: params.standardCode.trim(),
testCaseCount: params.testCaseCount,
serviceLevel: params.serviceLevel || "standard",
createdAt: new Date(),
updatedAt: new Date(),
progress: 0,
errorMessage: null,
generatedCases: 0,
};
tasks.set(taskId, task);
return task;
}
export function findRunningTaskByEnglishName(englishName: string): Task | undefined {
const name = englishName.trim().toLowerCase();
for (const task of tasks.values()) {
if (task.englishName === name && (task.status === "pending" || task.status === "running")) {
return task;
}
}
return undefined;
}
export function getEstimatedTime(serviceLevel: string, caseCount: number): number {
const baseTime = Math.ceil(caseCount / 2);
const multiplier: Record<string, number> = {
standard: 1.0,
domestic: 1.5,
pro: 1.2,
max: 2.0,
};
return Math.max(30, baseTime * (multiplier[serviceLevel] ?? 1.0));
}