From ec10e338e93c2fe0f9697e50dbe8be8af220d5df Mon Sep 17 00:00:00 2001 From: maayarosama Date: Sun, 15 Dec 2024 12:36:24 +0200 Subject: [PATCH 1/5] Select rented node in automated selection in case of its existence --- packages/playground/src/utils/nodeSelector.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/playground/src/utils/nodeSelector.ts b/packages/playground/src/utils/nodeSelector.ts index 1a87bacf80..1b5661ea59 100644 --- a/packages/playground/src/utils/nodeSelector.ts +++ b/packages/playground/src/utils/nodeSelector.ts @@ -8,7 +8,7 @@ import { z } from "zod"; import { gqlClient, gridProxyClient } from "../clients"; import type { usePagination } from "../hooks"; -import type { useGrid } from "../stores"; +import { type useGrid, useProfileManager } from "../stores"; import type { Locations, NormalizeFarmFiltersOptions, @@ -336,9 +336,21 @@ export async function selectValidNode( locked = false; await nodesLock.acquireAsync(); } + const profileManager = useProfileManager(); + let node; + node = nodes.find(n => { + return n.rentedByTwinId === profileManager?.profile?.twinId; + }); + + if (node && isNodeValid(getFarm, node, selectedMachines, filters)) { + if (nodesLock && !locked) { + release(nodesLock); + } + return node; + } if (oldSelectedNodeId) { - const node = nodes.find(n => n.nodeId === oldSelectedNodeId); + node = nodes.find(n => n.nodeId === oldSelectedNodeId); if (node && isNodeValid(getFarm, node, selectedMachines, filters)) { if (nodesLock && !locked) { From ddaea05b0dd267b1d2860d45ad68db8e3473e4c7 Mon Sep 17 00:00:00 2001 From: maayarosama Date: Mon, 16 Dec 2024 16:23:04 +0200 Subject: [PATCH 2/5] Use gridStore instead of profile and some refactor to code --- .../node_selector/TfAutoNodeSelector.vue | 1 + packages/playground/src/utils/nodeSelector.ts | 28 ++++++------------- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/packages/playground/src/components/node_selector/TfAutoNodeSelector.vue b/packages/playground/src/components/node_selector/TfAutoNodeSelector.vue index abd4e6f3e9..f86c3fff12 100644 --- a/packages/playground/src/components/node_selector/TfAutoNodeSelector.vue +++ b/packages/playground/src/components/node_selector/TfAutoNodeSelector.vue @@ -221,6 +221,7 @@ export default { async function _setValidNode(oldNodeId?: number) { const node = await selectValidNode( + gridStore, props.getFarm, _loadedNodes.value, props.selectedMachines, diff --git a/packages/playground/src/utils/nodeSelector.ts b/packages/playground/src/utils/nodeSelector.ts index 1b5661ea59..71b6880b3e 100644 --- a/packages/playground/src/utils/nodeSelector.ts +++ b/packages/playground/src/utils/nodeSelector.ts @@ -8,7 +8,7 @@ import { z } from "zod"; import { gqlClient, gridProxyClient } from "../clients"; import type { usePagination } from "../hooks"; -import { type useGrid, useProfileManager } from "../stores"; +import { type useGrid } from "../stores"; import type { Locations, NormalizeFarmFiltersOptions, @@ -324,6 +324,7 @@ export function isNodeValid( } export async function selectValidNode( + gridStore: ReturnType, getFarm: GetFarmFn, nodes: NodeInfo[], selectedMachines: SelectedMachine[], @@ -331,26 +332,13 @@ export async function selectValidNode( oldSelectedNodeId?: number, nodesLock?: AwaitLock, ): Promise { - let locked = true; - if (nodesLock && !nodesLock.acquired) { - locked = false; - await nodesLock.acquireAsync(); - } - const profileManager = useProfileManager(); - let node; - node = nodes.find(n => { - return n.rentedByTwinId === profileManager?.profile?.twinId; - }); + const locked = true; - if (node && isNodeValid(getFarm, node, selectedMachines, filters)) { - if (nodesLock && !locked) { - release(nodesLock); - } - return node; - } - - if (oldSelectedNodeId) { - node = nodes.find(n => n.nodeId === oldSelectedNodeId); + const rentedNode = nodes.find(n => { + return n.rentedByTwinId === gridStore.grid.twinId; + }); + if (oldSelectedNodeId || rentedNode) { + const node = rentedNode || nodes.find(n => n.nodeId === oldSelectedNodeId); if (node && isNodeValid(getFarm, node, selectedMachines, filters)) { if (nodesLock && !locked) { From 855383da7beffe3c48f4833bd94a0bbb2c8093a4 Mon Sep 17 00:00:00 2001 From: maayarosama Date: Mon, 16 Dec 2024 16:35:40 +0200 Subject: [PATCH 3/5] fix build error --- packages/playground/src/utils/nodeSelector.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/playground/src/utils/nodeSelector.ts b/packages/playground/src/utils/nodeSelector.ts index 71b6880b3e..685080fc95 100644 --- a/packages/playground/src/utils/nodeSelector.ts +++ b/packages/playground/src/utils/nodeSelector.ts @@ -8,7 +8,7 @@ import { z } from "zod"; import { gqlClient, gridProxyClient } from "../clients"; import type { usePagination } from "../hooks"; -import { type useGrid } from "../stores"; +import type { useGrid } from "../stores"; import type { Locations, NormalizeFarmFiltersOptions, @@ -335,7 +335,7 @@ export async function selectValidNode( const locked = true; const rentedNode = nodes.find(n => { - return n.rentedByTwinId === gridStore.grid.twinId; + n.rentedByTwinId === gridStore.grid.twinId; }); if (oldSelectedNodeId || rentedNode) { const node = rentedNode || nodes.find(n => n.nodeId === oldSelectedNodeId); From 8bf258dd2a822d1c81d0c66819ddb5775b97a2cb Mon Sep 17 00:00:00 2001 From: maayarosama Date: Tue, 17 Dec 2024 08:27:01 +0200 Subject: [PATCH 4/5] Getting all my rented node and choosing first one that's not in grace period --- packages/playground/src/utils/nodeSelector.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/playground/src/utils/nodeSelector.ts b/packages/playground/src/utils/nodeSelector.ts index 685080fc95..4ab1d67440 100644 --- a/packages/playground/src/utils/nodeSelector.ts +++ b/packages/playground/src/utils/nodeSelector.ts @@ -334,9 +334,23 @@ export async function selectValidNode( ): Promise { const locked = true; - const rentedNode = nodes.find(n => { - n.rentedByTwinId === gridStore.grid.twinId; + const rentedNodes = nodes.filter(n => { + return n.rentedByTwinId === gridStore.grid.twinId; }); + let rentedNode; + for (const node of rentedNodes) { + if (node.rentedByTwinId === gridStore.grid.twinId) { + const contractInfo = await gridStore.grid.contracts.get({ + id: node.rentContractId, + }); + + if (!contractInfo.state.gracePeriod) { + rentedNode = node; + break; + } + } + } + if (oldSelectedNodeId || rentedNode) { const node = rentedNode || nodes.find(n => n.nodeId === oldSelectedNodeId); From 606fa066310b1c5a54a8b3b03ef4bced8a51d93d Mon Sep 17 00:00:00 2001 From: maayarosama Date: Wed, 18 Dec 2024 14:29:47 +0200 Subject: [PATCH 5/5] In case if the user already chosen a node and reloded the noded, the old selected node will be picked --- packages/playground/src/utils/nodeSelector.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/playground/src/utils/nodeSelector.ts b/packages/playground/src/utils/nodeSelector.ts index 4ab1d67440..cb37068d2d 100644 --- a/packages/playground/src/utils/nodeSelector.ts +++ b/packages/playground/src/utils/nodeSelector.ts @@ -352,7 +352,7 @@ export async function selectValidNode( } if (oldSelectedNodeId || rentedNode) { - const node = rentedNode || nodes.find(n => n.nodeId === oldSelectedNodeId); + const node = nodes.find(n => n.nodeId === oldSelectedNodeId) || rentedNode; if (node && isNodeValid(getFarm, node, selectedMachines, filters)) { if (nodesLock && !locked) {