Skip to content

Commit

Permalink
agent: allow expired allocations to be reallocated with force
Browse files Browse the repository at this point in the history
  • Loading branch information
dwerner committed Oct 23, 2024
1 parent c0933a7 commit 3801b49
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/indexer-common/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,15 @@ export const validateActionInputs = async (
// allocationID must belong to active allocation
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const allocation = await networkMonitor.allocation(action.allocationID!)
if (allocation.status !== AllocationStatus.ACTIVE) {

const forcedReallocate =
action.type === ActionType.REALLOCATE &&
action.force === true &&
isZeroPOI(action.poi)

if (forcedReallocate) {
logger.info(`forcing reallocate of id = '${action.allocationID}'`)
} else if (allocation.status !== AllocationStatus.ACTIVE) {
throw new Error(
`An active allocation does not exist with id = '${action.allocationID}'`,
)
Expand All @@ -151,6 +159,10 @@ export const validateActionInputs = async (
}
}
}

function isZeroPOI(poi: string | undefined): boolean {
return (typeof poi == 'number' && poi == 0) || (typeof poi == 'string' && poi == '0')
}
}

export interface ActionFilter {
Expand Down

0 comments on commit 3801b49

Please sign in to comment.