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

Select rented node in automated selection in case of its existence #3749

Open
wants to merge 5 commits into
base: development
Choose a base branch
from
Open
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 @@ -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
Loading