Skip to content

Commit

Permalink
Add algorithm metadata if it does not exist. (#539)
Browse files Browse the repository at this point in the history
* Add algorithm metadata if it does not exist.

* tweak.

* fix part of review.

* Make format optional.

* destructing container object.
  • Loading branch information
mariacarmina authored Jul 31, 2024
1 parent 0b42285 commit 926f201
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/@types/DDO/Metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export interface MetadataAlgorithm {
* @type {string}
*/
rawcode?: string
/**
* Format of the algorithm
* @type {string}
*/
format?: string

/**
* Object describing the Docker container image.
Expand Down
15 changes: 14 additions & 1 deletion src/components/core/compute/startCompute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class ComputeStartHandler extends Handler {
const node = this.getOceanNode()
const assets: ComputeAsset[] = [task.dataset]
if (task.additionalDatasets) assets.push(...task.additionalDatasets)
const { algorithm } = task
let foundValidCompute = null

const algoChecksums = await getAlgoChecksums(
Expand Down Expand Up @@ -245,6 +246,18 @@ export class ComputeStartHandler extends Handler {
validUntil: validFee.validUntil
}
}
if (!('meta' in algorithm) && ddo.metadata.type === 'algorithm') {
const { entrypoint, image, tag, checksum } = ddo.metadata.algorithm.container
const container = { entrypoint, image, tag, checksum }
algorithm.meta = {
language: ddo.metadata.algorithm.language,
version: ddo.metadata.algorithm.version,
container: container

Check warning on line 255 in src/components/core/compute/startCompute.ts

View workflow job for this annotation

GitHub Actions / lint

Expected property shorthand
}
if ('format' in ddo.metadata.algorithm) {
algorithm.meta.format = ddo.metadata.algorithm.format
}
}
}
}
if (!foundValidCompute) {
Expand All @@ -265,7 +278,7 @@ export class ComputeStartHandler extends Handler {

const response = await engine.startComputeJob(
assets,
task.algorithm,
algorithm,
task.output,
task.consumerAddress,
envId,
Expand Down

0 comments on commit 926f201

Please sign in to comment.