From eb2760b15cfc63e409cd1ed1e68c053109785904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ola=20Flisb=C3=A4ck?= Date: Mon, 10 Oct 2022 15:16:19 +0200 Subject: [PATCH] feat: getExecutionStatus and async executeExperiment --- src/Client.ts | 54 ++++++++++++++++++++++++-------------------- src/types/index.d.ts | 3 +++ 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/Client.ts b/src/Client.ts index d4ef317..5916bae 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -5,6 +5,7 @@ import { Case, CaseTrajectories, CustomFunction, + ExecutionStatus, ExperimentId, ExperimentTrajectories, Workspace, @@ -39,20 +40,6 @@ const getValueFromJarCookies = (key: string, cookies: Cookie[]): string => { return cookie.value } -export interface Progress { - message: string - percentage: number - done: boolean - stage: string -} - -export interface CompilationStatus { - finished_executions: number - total_executions: number - status: string - progresses: Progress[] -} - export class Client { private axios: AxiosInstance private axiosConfig: AxiosConfig @@ -294,13 +281,13 @@ export class Client { }) } - private getExecutionStatus({ + getExecutionStatus({ experimentId, workspaceId, }: { experimentId: string workspaceId: string - }): Promise { + }): Promise { return new Promise((resolve, reject) => { this.ensureImpactToken() .then(() => { @@ -328,14 +315,10 @@ export class Client { }) while (data.status !== 'done') { await sleep(1000) - try { - data = await this.getExecutionStatus({ - experimentId, - workspaceId, - }) - } catch (e) { - throw e - } + data = await this.getExecutionStatus({ + experimentId, + workspaceId, + }) } } @@ -359,6 +342,29 @@ export class Client { workspaceId, }) + return experimentId + } + + async executeExperimentSync({ + caseIds, + experiment, + workspaceId, + }: { + caseIds: string[] + experiment: ModelicaExperiment + workspaceId: string + }): Promise { + const experimentId = await this.setupExperiment({ + experiment, + workspaceId, + }) + + await this.runExperiment({ + cases: caseIds, + experimentId, + workspaceId, + }) + await this.executionSuccess({ experimentId, workspaceId, diff --git a/src/types/index.d.ts b/src/types/index.d.ts index 7e3fc44..11d1308 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -5,6 +5,9 @@ export type Case = components['schemas']['Case'] export type CustomFunction = operations['getCustomFunction']['responses']['200']['content']['application/json'] +export type ExecutionStatus = + operations['getExecutionStatus']['responses']['200']['content']['application/json'] + export type Workspace = components['schemas']['Workspace'] export type ModelicaExperimentDefinition =