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

indexer-cli: command to batch approve queued #463

Merged
merged 1 commit into from
Aug 22, 2022
Merged
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
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> ...]
hopeyen marked this conversation as resolved.
Show resolved Hide resolved
${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 @@ -128,6 +128,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