1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

Merge pull request #372 from oceanprotocol/feature/compute-output

Adding output section
This commit is contained in:
Matthias Kretschmann 2020-02-03 10:55:14 +01:00 committed by GitHub
commit fd8ad9d96b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 4 deletions

View File

@ -4,7 +4,7 @@ import { noZeroX } from '../utils'
import { Instantiable, InstantiableConfig } from '../Instantiable.abstract'
import { DDO } from '../ddo/DDO'
import { ServiceType } from '../ddo/Service'
import { ComputeJob } from '../ocean/OceanCompute'
import { ComputeJob, Output } from '../ocean/OceanCompute'
const apiPath = '/api/v1/brizo/services'
@ -116,7 +116,8 @@ export class Brizo extends Instantiable {
consumerAccount: Account,
algorithmDid?: string,
algorithmMeta?: MetaData,
jobId?: string
jobId?: string,
output?: Output
): Promise<ComputeJob | ComputeJob[]> {
const signature = await this.createSignature(consumerAccount, serviceAgreementId)
const address = consumerAccount.getId()
@ -138,6 +139,7 @@ export class Brizo extends Instantiable {
url += `&serviceAgreementId=${noZeroX(serviceAgreementId)}`
url += algorithmDid && `&algorithmDid=${algorithmDid}`
url += algorithmMeta && `&algorithmMeta=${algorithmMeta}`
url += output && `&output=${output}`
url += jobId && `&jobId=${jobId}`
// switch fetch method

View File

@ -17,6 +17,19 @@ export enum ComputeJobStatus {
Deleted
}
export interface Output {
publishAlgorithmLog?: boolean
publishOutput?: boolean
brizoAddress?: string
brizoUri?: string
metadata?: MetaData
metadataUri?: string
nodeUri?: string
owner?: string
secretStoreUri?: string
whitelist?: string[]
}
export interface ComputeJob {
owner: string
agreementId: string
@ -74,26 +87,60 @@ export class OceanCompute extends Instantiable {
})
}
/**
* Check the output object and add default properties if needed
* @param {Account} consumerAccount The account of the consumer ordering the service.
* @param {Output} output Output section used for publishing the result.
* @return {Promise<Output>} Returns output object
*/
private checkOutput(consumerAccount: Account, output?: Output): Output {
const isDefault =
!output || (!output.publishAlgorithmLog && !output.publishOutput)
if (isDefault) {
return {
publishAlgorithmLog: false,
publishOutput: false
}
}
return {
publishAlgorithmLog: output.publishAlgorithmLog,
publishOutput: output.publishOutput,
brizoAddress: output.brizoAddress || this.config.brizoAddress,
brizoUri: output.brizoUri || this.config.brizoUri,
metadataUri: output.metadataUri || this.config.aquariusUri,
nodeUri: output.nodeUri || this.config.nodeUri,
owner: output.owner || consumerAccount.getId(),
secretStoreUri: output.secretStoreUri || this.config.secretStoreUri
}
}
/**
* Start the execution of a compute job.
* @param {Account} consumerAccount The account of the consumer ordering the service.
* @param {string} agreementId The service agreement ID.
* @param {string} algorithmDid The DID of the algorithm asset (of type `algorithm`) to run on the asset.
* @param {MetaData} algorithmMeta Metadata about the algorithm being run if `algorithm` is being used. This is ignored when `algorithmDid` is specified.
* @param {Output} output Define algorithm output publishing. Publishing the result of a compute job is turned off by default.
* @return {Promise<ComputeJob>} Returns compute job ID under status.jobId
*/
public async start(
consumerAccount: Account,
agreementId: string,
algorithmDid?: string,
algorithmMeta?: MetaData
algorithmMeta?: MetaData,
output?: Output
): Promise<ComputeJob> {
output = this.checkOutput(consumerAccount, output)
const status = await this.ocean.brizo.compute(
'post',
agreementId,
consumerAccount,
algorithmDid,
algorithmMeta
algorithmMeta,
null,
output
)
return status as ComputeJob