Skip to content

Commit

Permalink
fix getComputeJobResult and getComputeJobStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcos20 committed Oct 7, 2024
1 parent 610bc4e commit d26a8c5
Showing 1 changed file with 67 additions and 6 deletions.
73 changes: 67 additions & 6 deletions src/components/c2d/compute_engine_docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import type {
ComputeAsset,
ComputeJob,
ComputeOutput,
DBComputeJob
DBComputeJob,
ComputeResult
} from '../../@types/C2D/C2D.js'
import { ZeroAddress } from 'ethers'
// import { getProviderFeeToken } from '../../components/core/utils/feesHandler.js'
Expand All @@ -19,7 +20,15 @@ import { Storage } from '../storage/index.js'
import Dockerode from 'dockerode'
import type { ContainerCreateOptions, VolumeCreateOptions } from 'dockerode'
import * as tar from 'tar'
import { createWriteStream, existsSync, mkdirSync, rmSync, writeFileSync } from 'fs'
import {
createWriteStream,
existsSync,
mkdirSync,
rmSync,
writeFileSync,
statSync,
createReadStream
} from 'fs'
import { pipeline } from 'node:stream/promises'

export class C2DEngineDocker extends C2DEngine {
Expand Down Expand Up @@ -147,18 +156,51 @@ export class C2DEngineDocker extends C2DEngine {
return null
}

// eslint-disable-next-line require-await
private async getResults(jobId: string): Promise<ComputeResult[]> {
const res: ComputeResult[] = []
let index = 0
const logStat = statSync(

Check warning on line 163 in src/components/c2d/compute_engine_docker.ts

View workflow job for this annotation

GitHub Actions / lint

Found statSync from package "fs" with non literal argument at index 0
this.getC2DConfig().tempFolder + '/' + jobId + '/data/logs/algorithmLog'
)
if (logStat) {
res.push({
filename: 'algorithmLog',
filesize: logStat.size,
type: 'algorithmLog',
index
})
index = index + 1
}
const outputStat = statSync(

Check warning on line 175 in src/components/c2d/compute_engine_docker.ts

View workflow job for this annotation

GitHub Actions / lint

Found statSync from package "fs" with non literal argument at index 0
this.getC2DConfig().tempFolder + '/' + jobId + '/data/outputs/outputs.tar'
)
if (outputStat) {
res.push({
filename: 'outputs.tar',
filesize: outputStat.size,
type: 'output',
index
})
index = index + 1
}
return res
}

// eslint-disable-next-line require-await
public override async getComputeJobStatus(
consumerAddress?: string,
agreementId?: string,
jobId?: string
): Promise<ComputeJob[]> {
const job = await this.db.getJob(jobId)
if (job) {
const res: ComputeJob[] = [job as ComputeJob]
return res
if (!job) {
return []
}
return null
const res: ComputeJob = job as ComputeJob
// add results for algoLogs
res.results = await this.getResults(job.jobId)
return [res]
}

// eslint-disable-next-line require-await
Expand All @@ -167,6 +209,25 @@ export class C2DEngineDocker extends C2DEngine {
jobId: string,
index: number
): Promise<Readable> {
const job = await this.db.getJob(jobId)
if (!job) {
return null
}
const results = await this.getResults(jobId)
for (const i of results) {
if (i.index === index) {
if (i.type === 'algorithmLog') {
return createReadStream(

Check warning on line 220 in src/components/c2d/compute_engine_docker.ts

View workflow job for this annotation

GitHub Actions / lint

Found createReadStream from package "fs" with non literal argument at index 0
this.getC2DConfig().tempFolder + '/' + jobId + '/data/logs/algorithmLog'
)
}
if (i.type === 'output') {
return createReadStream(

Check warning on line 225 in src/components/c2d/compute_engine_docker.ts

View workflow job for this annotation

GitHub Actions / lint

Found createReadStream from package "fs" with non literal argument at index 0
this.getC2DConfig().tempFolder + '/' + jobId + '/data/outputs/outputs.tar'
)
}
}
}
return null
}

Expand Down

0 comments on commit d26a8c5

Please sign in to comment.