Skip to content
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
1 change: 1 addition & 0 deletions src/components/c2d/compute_engine_docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,7 @@ export class C2DEngineDocker extends C2DEngine {
follow: true
})
} catch (e) {
CORE_LOGGER.error(`getStreamableLogs failed for job ${jobId}: ${e?.message ?? e}`)
return null
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/components/core/compute/getStreamableLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ export class ComputeGetStreamableLogsHandler extends CommandHandler {
return {
stream: null,
status: {
httpStatus: 404
httpStatus: 404,
error: 'Job not found or not running'
}
}
}
Expand All @@ -80,12 +81,13 @@ export class ComputeGetStreamableLogsHandler extends CommandHandler {

return response
} catch (error) {
CORE_LOGGER.error(error.message)
const message = (error as Error)?.message ?? String(error)
CORE_LOGGER.error(message)
return {
stream: null,
status: {
httpStatus: 500,
error: error.message
error: message
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/components/httpRoutes/compute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,10 @@ computeRoutes.get(`${SERVICES_API_BASE_PATH}/computeStreamableLogs`, async (req,
res.set(response.status.headers)
response.stream.pipe(res)
} else {
res.status(response.status.httpStatus).send(response.status.error)
const body =
response.status.error ??
(response.status.httpStatus === 404 ? 'Job not found or not running' : 'Error')
res.status(response.status.httpStatus).send(body)
}
} catch (error) {
HTTP_LOGGER.log(LOG_LEVELS_STR.LEVEL_ERROR, `Error: ${error}`)
Expand Down
20 changes: 20 additions & 0 deletions src/test/unit/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ComputeGetEnvironmentsCommand,
ComputeGetResultCommand,
ComputeGetStatusCommand,
ComputeGetStreamableLogsCommand,
ComputeInitializeCommand,
PaidComputeStartCommand,
ComputeStopCommand,
Expand Down Expand Up @@ -47,6 +48,7 @@ import { PaidComputeStartHandler } from '../../components/core/compute/startComp
import { ComputeStopHandler } from '../../components/core/compute/stopCompute.js'
import { ComputeGetStatusHandler } from '../../components/core/compute/getStatus.js'
import { ComputeGetResultHandler } from '../../components/core/compute/getResults.js'
import { ComputeGetStreamableLogsHandler } from '../../components/core/compute/getStreamableLogs.js'
import { ComputeInitializeHandler } from '../../components/core/compute/initialize.js'
import { StopNodeHandler } from '../../components/core/admin/stopNodeHandler.js'
import { ReindexTxHandler } from '../../components/core/admin/reindexTxHandler.js'
Expand Down Expand Up @@ -358,6 +360,24 @@ describe('Commands and handlers', () => {
}
expect(resultEnvHandler.validate(resultEnvCommand).valid).to.be.equal(false)

// -----------------------------------------
// ComputeGetStreamableLogsHandler
const streamableLogsHandler: ComputeGetStreamableLogsHandler =
CoreHandlersRegistry.getInstance(node).getHandler(
PROTOCOL_COMMANDS.COMPUTE_GET_STREAMABLE_LOGS
)
const streamableLogsCommand: ComputeGetStreamableLogsCommand = {
command: PROTOCOL_COMMANDS.COMPUTE_GET_STREAMABLE_LOGS,
consumerAddress: 'abcdef',
jobId: 'hash-jobid',
signature: '',
nonce: ''
}
expect(streamableLogsHandler.validate(streamableLogsCommand).valid).to.be.equal(false)
streamableLogsCommand.consumerAddress = '0x8F292046bb73595A978F4e7A131b4EBd03A15e8a'
streamableLogsCommand.jobId = undefined
expect(streamableLogsHandler.validate(streamableLogsCommand).valid).to.be.equal(false)

// -----------------------------------------
// ComputeInitializeHandler
const initComputeHandler: ComputeInitializeHandler = CoreHandlersRegistry.getInstance(
Expand Down
Loading