Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle rented node in grace period #3742

Draft
wants to merge 7 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ import { RequestError } from "@threefold/types";
import type AwaitLock from "await-lock";
import equals from "lodash/fp/equals.js";
import { computed, nextTick, onMounted, onUnmounted, type PropType, ref } from "vue";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import type { VCard } from "vuetify/components/VCard";

import { normalizeError } from "@/utils/helpers";

import { useAsync, usePagination, useWatchDeep } from "../../hooks";
import { ValidatorStatus } from "../../hooks/form_validator";
Expand All @@ -167,7 +167,6 @@ import {
validateRentContract,
} from "../../utils/nodeSelector";
import TfNodeDetailsCard from "./TfNodeDetailsCard.vue";

export default {
name: "TfAutoNodeSelector",
components: { TfNodeDetailsCard },
Expand Down Expand Up @@ -299,14 +298,29 @@ export default {

const nodeInputValidateTask = useAsync<boolean, string, [NodeInfo | undefined]>(
async node => {
if (node && node?.rentContractId !== 0) {
const { state } = await gridStore.grid.contracts.get({
id: node?.rentContractId,
});
if (state.gracePeriod) {
return false;
try {
if (node && node.rentContractId !== 0) {
const { state } = await gridStore.grid.contracts.get({
id: node?.rentContractId,
});
if (state.gracePeriod) {
const err = `You can't deploy on node ${node.nodeId}, its rent contract is in grace period.`;
await new Promise((_, reject) => {
setTimeout(() => {
reject(Error(err));
}, 2000);
});
console.error(err);
}
}
} catch (error) {
const err = normalizeError(
error,
"Something went wrong while checking status of the node. Please check your connection and try again.",
);
throw err;
}

const nodeCapacityValid = await checkNodeCapacityPool(gridStore, node, props.filters);
const rentContractValid = props.filters.dedicated ? await validateRentContract(gridStore, node) : true;

Expand Down
12 changes: 7 additions & 5 deletions packages/playground/src/utils/nodeSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import type {
SelectionDetailsFilters,
SelectionDetailsFiltersValidators,
} from "../types/nodeSelector";
import { createCustomToast, ToastType } from "./custom_toast";
import { normalizeError } from "./helpers";

export interface GetLocationsConfig {
Expand Down Expand Up @@ -229,10 +228,13 @@ export async function validateRentContract(
id: node.rentContractId,
});
if (contractInfo.state.gracePeriod) {
createCustomToast(
`You can't deploy on node ${node.nodeId}, its rent contract is in grace period.`,
ToastType.danger,
);
const err = `You can't deploy on node ${node.nodeId}, its rent contract is in grace period.`;
await new Promise((_, reject) => {
setTimeout(() => {
reject(Error(err));
}, 2000);
});
console.error(err);
}
}

Expand Down
Loading