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 1a87bacf80..cb37068d2d 100644 --- a/packages/playground/src/utils/nodeSelector.ts +++ b/packages/playground/src/utils/nodeSelector.ts @@ -324,6 +324,7 @@ export function isNodeValid( } export async function selectValidNode( + gridStore: ReturnType<typeof useGrid>, getFarm: GetFarmFn, nodes: NodeInfo[], selectedMachines: SelectedMachine[], @@ -331,14 +332,27 @@ export async function selectValidNode( oldSelectedNodeId?: number, nodesLock?: AwaitLock, ): Promise<NodeInfo | void> { - let locked = true; - if (nodesLock && !nodesLock.acquired) { - locked = false; - await nodesLock.acquireAsync(); + const locked = true; + + 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) { - const node = nodes.find(n => n.nodeId === oldSelectedNodeId); + if (oldSelectedNodeId || rentedNode) { + const node = nodes.find(n => n.nodeId === oldSelectedNodeId) || rentedNode; if (node && isNodeValid(getFarm, node, selectedMachines, filters)) { if (nodesLock && !locked) {