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

feat(cli): show elapsed time for each step #620

Merged
merged 1 commit into from
Dec 9, 2023
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
15 changes: 12 additions & 3 deletions fullstack-network-manager/src/commands/chart.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ export class ChartCommand extends BaseCommand {
)
}
}
])
], {
concurrent: false,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})

try {
await tasks.run()
Expand Down Expand Up @@ -125,7 +128,10 @@ export class ChartCommand extends BaseCommand {
await self.chartManager.uninstall(ctx.config.namespace, constants.CHART_FST_DEPLOYMENT_NAME)
}
}
])
], {
concurrent: false,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})

try {
await tasks.run()
Expand Down Expand Up @@ -167,7 +173,10 @@ export class ChartCommand extends BaseCommand {
)
}
}
])
], {
concurrent: false,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})

try {
await tasks.run()
Expand Down
20 changes: 16 additions & 4 deletions fullstack-network-manager/src/commands/cluster.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ export class ClusterCommand extends BaseCommand {
self.logger.showList('Kubernetes Contexts', ctx.kubeContexts)
}
}
])
], {
concurrent: false,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})

try {
await tasks.run()
Expand Down Expand Up @@ -203,7 +206,10 @@ export class ClusterCommand extends BaseCommand {
},
skip: (ctx, _) => !ctx.clusters.includes(ctx.config.clusterName)
}
])
], {
concurrent: false,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})

try {
await tasks.run()
Expand Down Expand Up @@ -289,7 +295,10 @@ export class ClusterCommand extends BaseCommand {
},
skip: (ctx, _) => ctx.isChartInstalled
}
])
], {
concurrent: false,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})

try {
await tasks.run()
Expand Down Expand Up @@ -337,7 +346,10 @@ export class ClusterCommand extends BaseCommand {
},
skip: (ctx, _) => !ctx.isChartInstalled
}
])
], {
concurrent: false,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})

try {
await tasks.run()
Expand Down
5 changes: 4 additions & 1 deletion fullstack-network-manager/src/commands/init.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ export class InitCommand extends BaseCommand {
self.logger.showJSON('Cached Config', ctx.config)
}
}
])
], {
concurrent: false,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})

try {
await tasks.run()
Expand Down
18 changes: 13 additions & 5 deletions fullstack-network-manager/src/commands/node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class NodeCommand extends BaseCommand {
}
], {
concurrent: false,
showErrorMessage: false
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})

try {
Expand Down Expand Up @@ -189,12 +189,16 @@ export class NodeCommand extends BaseCommand {
return task.newListr(subTasks, {
concurrent: true,
rendererOptions: {
collapseSubtasks: false
collapseSubtasks: false,
timer: constants.LISTR_DEFAULT_RENDERER_TIMER_OPTION
}
})
}
}
], { concurrent: false })
], {
concurrent: false,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})

try {
await tasks.run()
Expand Down Expand Up @@ -238,12 +242,16 @@ export class NodeCommand extends BaseCommand {
return task.newListr(subTasks, {
concurrent: true,
rendererOptions: {
collapseSubtasks: false
collapseSubtasks: false,
timer: constants.LISTR_DEFAULT_RENDERER_TIMER_OPTION
}
})
}
}
], { concurrent: false })
], {
concurrent: false,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})

try {
await tasks.run()
Expand Down
10 changes: 8 additions & 2 deletions fullstack-network-manager/src/commands/relay.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ export class RelayCommand extends BaseCommand {
this.logger.showList('Deployed Relays', await self.chartManager.getInstalledCharts(namespace))
}
}
])
], {
concurrent: false,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})

try {
await tasks.run()
Expand Down Expand Up @@ -190,7 +193,10 @@ export class RelayCommand extends BaseCommand {
this.logger.showList('Deployed Relays', await self.chartManager.getInstalledCharts(namespace))
}
}
])
], {
concurrent: false,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})

try {
await tasks.run()
Expand Down
18 changes: 18 additions & 0 deletions fullstack-network-manager/src/core/constants.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { color, PRESET_TIMER } from 'listr2'
import { dirname, normalize } from 'path'
import { fileURLToPath } from 'url'
import chalk from 'chalk'
Expand Down Expand Up @@ -53,3 +54,20 @@ export const DEFAULT_CHART_REPO = new Map()
.set(CHART_FST_REPO_NAME, CHART_REPO_FST_URL)
.set(CHART_JSON_RPC_RELAY_REPO_NAME, CHART_REPO_JSON_RPC_RELAY_URL)
.set(CHART_MIRROR_NODE_REPO_NAME, CHART_MIRROR_NODE_URL)

// Listr related
export const LISTR_DEFAULT_RENDERER_TIMER_OPTION = {
...PRESET_TIMER,
condition: (duration) => duration > 100,
format: (duration) => {
if (duration > 10000) {
return color.red
}

return color.green
}
}

export const LISTR_DEFAULT_RENDERER_OPTION = {
timer: LISTR_DEFAULT_RENDERER_TIMER_OPTION
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ describe('ShellRunner', () => {
it('should run command', async () => {
await shellRunner.run('ls -l')
expect(loggerSpy).toHaveBeenNthCalledWith(1, 'Executing command: \'ls -l\'')
expect(loggerSpy).toHaveBeenNthCalledWith(2,'Finished executing: \'ls -l\'', {
'commandExitCode': expect.any(Number),
'commandExitSignal': null,
'commandOutput': expect.any(Array)
expect(loggerSpy).toHaveBeenNthCalledWith(2, 'Finished executing: \'ls -l\'', {
commandExitCode: expect.any(Number),
commandExitSignal: null,
commandOutput: expect.any(Array)
})
expect(readableSpy).toHaveBeenCalledWith('data', expect.anything())
expect(childProcessSpy).toHaveBeenCalledWith('exit', expect.anything())
Expand Down
Loading