Skip to content

Commit

Permalink
Ignore the contract that the API returns when launching a service, we…
Browse files Browse the repository at this point in the history
… don't use it
  • Loading branch information
garronej committed Aug 31, 2023
1 parent 5eebd92 commit 0dfa8d0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 64 deletions.
10 changes: 4 additions & 6 deletions src/core/adapters/onyxiaApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,19 +677,19 @@ export function createOnyxiaApi(params: {
axiosInstance.get("/my-lab/app", { params }).catch(onError);

const launchPackage = id<OnyxiaApi["launchPackage"]>(
async ({ catalogId, packageName, options, isDryRun }) => {
async ({ catalogId, packageName, options }) => {
const { serviceId } = getServiceId({
packageName,
"randomK8sSubdomain": getRandomK8sSubdomain()
});

const { data: contract } = await axiosInstance
.put<Record<string, unknown>[][]>(`/my-lab/app`, {
await axiosInstance
.put(`/my-lab/app`, {
catalogId,
packageName,
"name": serviceId,
options,
"dryRun": isDryRun
"dryRun": false
})
.catch(onError);

Expand All @@ -701,8 +701,6 @@ export function createOnyxiaApi(params: {
await new Promise(resolve => setTimeout(resolve, 1000));
}
}

return { contract };
}
);

Expand Down
3 changes: 1 addition & 2 deletions src/core/ports/OnyxiaApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ export type OnyxiaApi = {
catalogId: string;
packageName: string;
options: Record<string, unknown>;
isDryRun: boolean;
}) => Promise<{ contract: Contract }>;
}) => Promise<void>;

getRunningServices: () => Promise<RunningService[]>;

Expand Down
77 changes: 21 additions & 56 deletions src/core/usecases/launcher/launcher.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import "minimal-polyfills/Object.fromEntries";
import type { State as RootState, Thunks } from "../../core";
import type { State as RootState, Thunks, CreateEvt } from "../../core";
import { createSelector, createSlice } from "@reduxjs/toolkit";
import { id } from "tsafe/id";
import { assert } from "tsafe/assert";
import { selectors as userConfigsSelectors } from "../userConfigs";
import { same } from "evt/tools/inDepth/same";
import { type FormFieldValue, formFieldsValueToObject } from "./FormField";
import type {
Contract,
JSONSchemaFormFieldDescription,
JSONSchemaObject,
OnyxiaValues
Expand All @@ -30,7 +29,6 @@ import { scaffoldingIndexedFormFieldsToFinal } from "./scaffoldingIndexedFormFie
import type { FormField, IndexedFormFields } from "./FormField";
import * as yaml from "yaml";
import type { Equals } from "tsafe";
import type { CreateEvt } from "../../core";
import { Evt } from "evt";

type State = State.NotInitialized | State.Ready;
Expand Down Expand Up @@ -92,7 +90,6 @@ export const { reducer, actions } = createSlice({
config: State.Ready["config"];
dependencies: string[];
formFieldsValueDifferentFromDefault: FormFieldValue[];
// NOTE: For coreEvt
sensitiveConfigurations: FormFieldValue[];
};
}
Expand Down Expand Up @@ -208,42 +205,6 @@ export const { reducer, actions } = createSlice({
})()
});

const privateThunks = {
"launchOrPreviewContract":
(params: { isForContractPreview: boolean }) =>
async (...args): Promise<{ contract: Contract }> => {
const { isForContractPreview } = params;

const [dispatch, getState, { onyxiaApi }] = args;

if (!isForContractPreview) {
dispatch(actions.launchStarted());
}

const state = getState().launcher;

assert(state.stateDescription === "ready");

const { contract } = await onyxiaApi.launchPackage({
"catalogId": state.catalogId,
"packageName": state.packageName,
"options": formFieldsValueToObject(state.formFields),
"isDryRun": isForContractPreview
});

if (!isForContractPreview) {
const { serviceId } = getServiceId({
"packageName": state.packageName,
"randomK8sSubdomain": getRandomK8sSubdomain()
});

dispatch(actions.launchCompleted({ serviceId }));
}

return { contract };
}
} satisfies Thunks;

export const thunks = {
"initialize":
(params: {
Expand Down Expand Up @@ -683,22 +644,26 @@ export const thunks = {
"launch":
() =>
async (...args) => {
const [dispatch] = args;
dispatch(
privateThunks.launchOrPreviewContract({
"isForContractPreview": false
})
);
},
"getContract":
() =>
async (...args): Promise<{ contract: Contract }> => {
const [dispatch] = args;
return dispatch(
privateThunks.launchOrPreviewContract({
"isForContractPreview": true
})
);
const [dispatch, getState, { onyxiaApi }] = args;

dispatch(actions.launchStarted());

const state = getState().launcher;

assert(state.stateDescription === "ready");

await onyxiaApi.launchPackage({
"catalogId": state.catalogId,
"packageName": state.packageName,
"options": formFieldsValueToObject(state.formFields)
});

const { serviceId } = getServiceId({
"packageName": state.packageName,
"randomK8sSubdomain": getRandomK8sSubdomain()
});

dispatch(actions.launchCompleted({ serviceId }));
},
"changeFriendlyName":
(friendlyName: string) =>
Expand Down

0 comments on commit 0dfa8d0

Please sign in to comment.