Skip to content

Commit

Permalink
feat: getExecutionStatus and async executeExperiment
Browse files Browse the repository at this point in the history
  • Loading branch information
x-oflisback committed Oct 10, 2022
1 parent 9cd0cff commit eb2760b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
54 changes: 30 additions & 24 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Case,
CaseTrajectories,
CustomFunction,
ExecutionStatus,
ExperimentId,
ExperimentTrajectories,
Workspace,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -294,13 +281,13 @@ export class Client {
})
}

private getExecutionStatus({
getExecutionStatus({
experimentId,
workspaceId,
}: {
experimentId: string
workspaceId: string
}): Promise<CompilationStatus> {
}): Promise<ExecutionStatus> {
return new Promise((resolve, reject) => {
this.ensureImpactToken()
.then(() => {
Expand Down Expand Up @@ -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,
})
}
}

Expand All @@ -359,6 +342,29 @@ export class Client {
workspaceId,
})

return experimentId
}

async executeExperimentSync({
caseIds,
experiment,
workspaceId,
}: {
caseIds: string[]
experiment: ModelicaExperiment
workspaceId: string
}): Promise<ExperimentId> {
const experimentId = await this.setupExperiment({
experiment,
workspaceId,
})

await this.runExperiment({
cases: caseIds,
experimentId,
workspaceId,
})

await this.executionSuccess({
experimentId,
workspaceId,
Expand Down
3 changes: 3 additions & 0 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit eb2760b

Please sign in to comment.