Skip to content

Commit

Permalink
Select rented node in automated selection in case of its existence (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
maayarosama authored Dec 30, 2024
1 parent f0f91d9 commit 2811f6d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ export default {
async function _setValidNode(oldNodeId?: number) {
const node = await selectValidNode(
gridStore,
props.getFarm,
_loadedNodes.value,
props.selectedMachines,
Expand Down
26 changes: 20 additions & 6 deletions packages/playground/src/utils/nodeSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,21 +324,35 @@ export function isNodeValid(
}

export async function selectValidNode(
gridStore: ReturnType<typeof useGrid>,
getFarm: GetFarmFn,
nodes: NodeInfo[],
selectedMachines: SelectedMachine[],
filters: FilterOptions,
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) {
Expand Down

0 comments on commit 2811f6d

Please sign in to comment.