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:
commit
fd8ad9d96b
@ -4,7 +4,7 @@ import { noZeroX } from '../utils'
|
|||||||
import { Instantiable, InstantiableConfig } from '../Instantiable.abstract'
|
import { Instantiable, InstantiableConfig } from '../Instantiable.abstract'
|
||||||
import { DDO } from '../ddo/DDO'
|
import { DDO } from '../ddo/DDO'
|
||||||
import { ServiceType } from '../ddo/Service'
|
import { ServiceType } from '../ddo/Service'
|
||||||
import { ComputeJob } from '../ocean/OceanCompute'
|
import { ComputeJob, Output } from '../ocean/OceanCompute'
|
||||||
|
|
||||||
const apiPath = '/api/v1/brizo/services'
|
const apiPath = '/api/v1/brizo/services'
|
||||||
|
|
||||||
@ -116,7 +116,8 @@ export class Brizo extends Instantiable {
|
|||||||
consumerAccount: Account,
|
consumerAccount: Account,
|
||||||
algorithmDid?: string,
|
algorithmDid?: string,
|
||||||
algorithmMeta?: MetaData,
|
algorithmMeta?: MetaData,
|
||||||
jobId?: string
|
jobId?: string,
|
||||||
|
output?: Output
|
||||||
): Promise<ComputeJob | ComputeJob[]> {
|
): Promise<ComputeJob | ComputeJob[]> {
|
||||||
const signature = await this.createSignature(consumerAccount, serviceAgreementId)
|
const signature = await this.createSignature(consumerAccount, serviceAgreementId)
|
||||||
const address = consumerAccount.getId()
|
const address = consumerAccount.getId()
|
||||||
@ -138,6 +139,7 @@ export class Brizo extends Instantiable {
|
|||||||
url += `&serviceAgreementId=${noZeroX(serviceAgreementId)}`
|
url += `&serviceAgreementId=${noZeroX(serviceAgreementId)}`
|
||||||
url += algorithmDid && `&algorithmDid=${algorithmDid}`
|
url += algorithmDid && `&algorithmDid=${algorithmDid}`
|
||||||
url += algorithmMeta && `&algorithmMeta=${algorithmMeta}`
|
url += algorithmMeta && `&algorithmMeta=${algorithmMeta}`
|
||||||
|
url += output && `&output=${output}`
|
||||||
url += jobId && `&jobId=${jobId}`
|
url += jobId && `&jobId=${jobId}`
|
||||||
|
|
||||||
// switch fetch method
|
// switch fetch method
|
||||||
|
@ -17,6 +17,19 @@ export enum ComputeJobStatus {
|
|||||||
Deleted
|
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 {
|
export interface ComputeJob {
|
||||||
owner: string
|
owner: string
|
||||||
agreementId: 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.
|
* Start the execution of a compute job.
|
||||||
* @param {Account} consumerAccount The account of the consumer ordering the service.
|
* @param {Account} consumerAccount The account of the consumer ordering the service.
|
||||||
* @param {string} agreementId The service agreement ID.
|
* @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 {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 {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
|
* @return {Promise<ComputeJob>} Returns compute job ID under status.jobId
|
||||||
*/
|
*/
|
||||||
public async start(
|
public async start(
|
||||||
consumerAccount: Account,
|
consumerAccount: Account,
|
||||||
agreementId: string,
|
agreementId: string,
|
||||||
algorithmDid?: string,
|
algorithmDid?: string,
|
||||||
algorithmMeta?: MetaData
|
algorithmMeta?: MetaData,
|
||||||
|
output?: Output
|
||||||
): Promise<ComputeJob> {
|
): Promise<ComputeJob> {
|
||||||
|
output = this.checkOutput(consumerAccount, output)
|
||||||
const status = await this.ocean.brizo.compute(
|
const status = await this.ocean.brizo.compute(
|
||||||
'post',
|
'post',
|
||||||
agreementId,
|
agreementId,
|
||||||
consumerAccount,
|
consumerAccount,
|
||||||
algorithmDid,
|
algorithmDid,
|
||||||
algorithmMeta
|
algorithmMeta,
|
||||||
|
null,
|
||||||
|
output
|
||||||
)
|
)
|
||||||
|
|
||||||
return status as ComputeJob
|
return status as ComputeJob
|
||||||
|
Loading…
Reference in New Issue
Block a user