mirror of
https://github.com/Crosstalk-Solutions/project-nomad.git
synced 2026-04-04 07:46:16 +02:00
refactor: deduplicate benchmark controller run methods into shared helper
Extract common logic from runSystem() and runAI() into a private _runBenchmark() helper that handles checking for running benchmarks, dispatching the job, and returning the response. https://claude.ai/code/session_01JFvpTYgm8GiE4vJ4cJKsFx
This commit is contained in:
parent
3fa373415b
commit
b959196381
|
|
@ -81,32 +81,21 @@ export default class BenchmarkController {
|
||||||
* Run a system-only benchmark (CPU, memory, disk)
|
* Run a system-only benchmark (CPU, memory, disk)
|
||||||
*/
|
*/
|
||||||
async runSystem({ response }: HttpContext) {
|
async runSystem({ response }: HttpContext) {
|
||||||
const status = this.benchmarkService.getStatus()
|
return this._runBenchmark('system', response)
|
||||||
if (status.status !== 'idle') {
|
|
||||||
return response.status(409).send({
|
|
||||||
success: false,
|
|
||||||
error: 'A benchmark is already running',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const benchmarkId = randomUUID()
|
|
||||||
await RunBenchmarkJob.dispatch({
|
|
||||||
benchmark_id: benchmarkId,
|
|
||||||
benchmark_type: 'system',
|
|
||||||
include_ai: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
return response.status(201).send({
|
|
||||||
success: true,
|
|
||||||
benchmark_id: benchmarkId,
|
|
||||||
message: 'System benchmark started',
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run an AI-only benchmark
|
* Run an AI-only benchmark
|
||||||
*/
|
*/
|
||||||
async runAI({ response }: HttpContext) {
|
async runAI({ response }: HttpContext) {
|
||||||
|
return this._runBenchmark('ai', response)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shared helper for dispatching a benchmark job.
|
||||||
|
* Checks for existing running benchmarks, dispatches the job, and returns the response.
|
||||||
|
*/
|
||||||
|
private async _runBenchmark(type: BenchmarkType, response: HttpContext['response']) {
|
||||||
const status = this.benchmarkService.getStatus()
|
const status = this.benchmarkService.getStatus()
|
||||||
if (status.status !== 'idle') {
|
if (status.status !== 'idle') {
|
||||||
return response.status(409).send({
|
return response.status(409).send({
|
||||||
|
|
@ -118,14 +107,14 @@ export default class BenchmarkController {
|
||||||
const benchmarkId = randomUUID()
|
const benchmarkId = randomUUID()
|
||||||
await RunBenchmarkJob.dispatch({
|
await RunBenchmarkJob.dispatch({
|
||||||
benchmark_id: benchmarkId,
|
benchmark_id: benchmarkId,
|
||||||
benchmark_type: 'ai',
|
benchmark_type: type,
|
||||||
include_ai: true,
|
include_ai: type === 'full' || type === 'ai',
|
||||||
})
|
})
|
||||||
|
|
||||||
return response.status(201).send({
|
return response.status(201).send({
|
||||||
success: true,
|
success: true,
|
||||||
benchmark_id: benchmarkId,
|
benchmark_id: benchmarkId,
|
||||||
message: 'AI benchmark started',
|
message: `${type === 'ai' ? 'AI' : type.charAt(0).toUpperCase() + type.slice(1)} benchmark started`,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user