fix(web): make backtest run controls and selection reliable
This commit is contained in:
parent
3d26da07f5
commit
67f12b49a0
8 changed files with 1109 additions and 675 deletions
|
|
@ -49,6 +49,13 @@ export interface CreateRunRequest {
|
|||
|
||||
export type RunResult = BacktestRunResult;
|
||||
|
||||
export class RunResultsUnavailableError extends Error {
|
||||
constructor() {
|
||||
super('Completed run results are not available');
|
||||
this.name = 'RunResultsUnavailableError';
|
||||
}
|
||||
}
|
||||
|
||||
export const backtestApiV2 = {
|
||||
// Backtest operations
|
||||
async createBacktest(request: CreateBacktestRequest): Promise<Backtest> {
|
||||
|
|
@ -144,8 +151,8 @@ export const backtestApiV2 = {
|
|||
return response.json();
|
||||
},
|
||||
|
||||
async getRun(id: string): Promise<Run> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/v2/runs/${id}`);
|
||||
async getRun(id: string, signal?: AbortSignal): Promise<Run> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/v2/runs/${id}`, { signal });
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to get run: ${response.statusText}`);
|
||||
|
|
@ -154,8 +161,12 @@ export const backtestApiV2 = {
|
|||
return response.json();
|
||||
},
|
||||
|
||||
async getRunResults(runId: string): Promise<RunResult> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/v2/runs/${runId}/results`);
|
||||
async getRunResults(runId: string, signal?: AbortSignal): Promise<RunResult> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/v2/runs/${runId}/results`, { signal });
|
||||
|
||||
if (response.status === 404) {
|
||||
throw new RunResultsUnavailableError();
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to get run results: ${response.status} ${response.statusText}`);
|
||||
|
|
@ -184,9 +195,10 @@ export const backtestApiV2 = {
|
|||
}
|
||||
},
|
||||
|
||||
async cancelRun(id: string): Promise<void> {
|
||||
async cancelRun(id: string, signal?: AbortSignal): Promise<void> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/v2/runs/${id}/cancel`, {
|
||||
method: 'POST',
|
||||
signal,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue