Skip to content

Commit

Permalink
indexer-cli: command to batch approve queued
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen authored and hopeyen committed Aug 22, 2022
1 parent 43757da commit 6ac45fc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
22 changes: 17 additions & 5 deletions packages/indexer-cli/src/commands/indexer/actions/approve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import chalk from 'chalk'
import { loadValidatedConfig } from '../../../config'
import { createIndexerManagementClient } from '../../../client'
import { fixParameters, printObjectOrArray } from '../../../command-helpers'
import { approveActions } from '../../../actions'
import { approveActions, fetchActions } from '../../../actions'
import { ActionStatus } from '@graphprotocol/indexer-common'

const HELP = `
${chalk.bold('graph indexer actions approve')} [options] [<actionID1> ...]
${chalk.bold('graph indexer actions approve')} [options] queued
${chalk.dim('Options:')}
Expand Down Expand Up @@ -37,6 +39,8 @@ module.exports = {

let numericActionIDs: number[]

const config = loadValidatedConfig()
const client = await createIndexerManagementClient({ url: config.api })
try {
if (!['json', 'yaml', 'table'].includes(outputFormat)) {
throw Error(
Expand All @@ -48,7 +52,18 @@ module.exports = {
throw Error(`Missing required argument: 'actionID'`)
}

numericActionIDs = actionIDs.map(action => +action)
// If actionIDs is 'queued', then populate actionIDs with actions that are queued
if (actionIDs.join() == 'queued') {
const queuedActions = await fetchActions(client, {
status: ActionStatus.QUEUED,
})
numericActionIDs = queuedActions.map(action => action.id)
if (numericActionIDs.length === 0) {
throw Error(`No 'queued' actions found.`)
}
} else {
numericActionIDs = actionIDs.map(action => +action)
}

inputSpinner.succeed('Processed input parameters')
} catch (error) {
Expand All @@ -60,9 +75,6 @@ module.exports = {

const actionSpinner = toolbox.print.spin(`Approving ${actionIDs.length} actions`)
try {
const config = loadValidatedConfig()
const client = await createIndexerManagementClient({ url: config.api })

const queuedAction = await approveActions(client, numericActionIDs)

actionSpinner.succeed(`Actions approved`)
Expand Down
1 change: 1 addition & 0 deletions packages/indexer-common/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export interface ActionFilter {
}

export interface ActionResult {
id: number
type: ActionType
deploymentID: string
allocationID: string | null
Expand Down
1 change: 1 addition & 0 deletions packages/indexer-common/src/indexer-management/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ const SCHEMA_SDL = gql`
status: String!
transaction: String
failureReason: String
priority: Int
}
input ActionFilter {
Expand Down

0 comments on commit 6ac45fc

Please sign in to comment.