Skip to content

Commit

Permalink
refactor ⚙: Refactoring the confirmDeployment flow
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzoronzani committed Jun 19, 2024
1 parent a873f77 commit 51fe8a4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions frontend/app/dashboard/new-deployment/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {displayE8sAsIcp, icpToE8s} from "@/helpers/ui";
import {Spinner} from "@/components/spinner";
import {NewDeploymentForm} from "@/components/new-deployment-form";
import {transferE8sToBackend} from "@/services/backend";
import {sendManifestToProviderFlow} from "@/services/deployment";
import {confirmDeployment} from "@/services/deployment";

const FETCH_DEPLOYMENT_PRICE_INTERVAL_MS = 30_000; // 30 seconds

Expand Down Expand Up @@ -163,7 +163,7 @@ export default function NewDeployment() {
el.hasOwnProperty("DeploymentCreated")
)!;

await sendManifestToProviderFlow(
await confirmDeployment(
deploymentUpdate.update,
deploymentCreatedState,
tlsCertificateData!
Expand Down
8 changes: 5 additions & 3 deletions frontend/app/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
isDeploymentFailed,
} from "@/helpers/deployment";
import {displayIcp} from "@/helpers/ui";
import {queryLeaseStatus, sendManifestToProviderFlow} from "@/services/deployment";
import {confirmDeployment, queryLeaseStatus} from "@/services/deployment";
import {DeploymentTier} from "@/types/deployment";
import {ChevronsUpDown} from "lucide-react";
import {useRouter} from "next/navigation";
Expand Down Expand Up @@ -131,7 +131,7 @@ export default function Dashboard() {
try {
const cert = await loadOrCreateCertificate(backendActor!);

await sendManifestToProviderFlow(
await confirmDeployment(
lastState,
deploymentCreatedState,
cert!
Expand All @@ -147,8 +147,10 @@ export default function Dashboard() {
stepActive
)
);

await fetchDeployments(backendActor!);
} catch (e) {
console.error(e);
console.error("Failed to update deployment:", e);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion frontend/services/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const queryLeaseStatus = async (queryLeaseUrl: string, certData: X509Cert
return await res.json();
};

export const sendManifestToProviderFlow = async (deploymentState: DeploymentState, deploymentCreatedState: DeploymentState, cert: MTlsCertificateData) => {
export const confirmDeployment = async (deploymentState: DeploymentState, deploymentCreatedState: DeploymentState, cert: MTlsCertificateData) => {
try {
if ("LeaseCreated" in deploymentState) {
const {manifest_sorted_json, dseq} = extractDeploymentCreated(deploymentCreatedState);
Expand All @@ -94,6 +94,7 @@ export const sendManifestToProviderFlow = async (deploymentState: DeploymentStat
manifest_sorted_json,
cert!
);

} else {
throw new Error("Deployment state is not in LeaseCreated state");
}
Expand Down

0 comments on commit 51fe8a4

Please sign in to comment.