mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
job status cleanup
This commit is contained in:
parent
1d7105cfb1
commit
f11eacaabd
@ -1,7 +1,7 @@
|
|||||||
import { assert } from 'chai'
|
import { assert } from 'chai'
|
||||||
|
|
||||||
import { config } from '../config'
|
import { config } from '../config'
|
||||||
import { Ocean, Account, DDO, MetaData } from '../../src' // @oceanprotocol/squid
|
import { Ocean, Account, DDO, MetaData, ComputeJobStatus } from '../../src' // @oceanprotocol/squid
|
||||||
import { getMetadata, getComputeServiceExample } from '../utils'
|
import { getMetadata, getComputeServiceExample } from '../utils'
|
||||||
|
|
||||||
describe('Compute', () => {
|
describe('Compute', () => {
|
||||||
@ -62,6 +62,6 @@ describe('Compute', () => {
|
|||||||
it('should start a compute job', async () => {
|
it('should start a compute job', async () => {
|
||||||
const response = await ocean.compute.start(account, agreementId, ddoAlgorithm.id)
|
const response = await ocean.compute.start(account, agreementId, ddoAlgorithm.id)
|
||||||
|
|
||||||
assert.equal(response.status, 1)
|
assert.equal(response.status, ComputeJobStatus.Started)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -4,6 +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'
|
||||||
|
|
||||||
const apiPath = '/api/v1/brizo/services'
|
const apiPath = '/api/v1/brizo/services'
|
||||||
|
|
||||||
@ -116,7 +117,7 @@ export class Brizo extends Instantiable {
|
|||||||
algorithmDid?: string,
|
algorithmDid?: string,
|
||||||
algorithmMeta?: MetaData,
|
algorithmMeta?: MetaData,
|
||||||
jobId?: string
|
jobId?: string
|
||||||
): Promise<any> {
|
): 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()
|
||||||
const serviceEndpoint = await this.getEndpointFromAgreement(
|
const serviceEndpoint = await this.getEndpointFromAgreement(
|
||||||
|
@ -5,13 +5,24 @@ import { DDO } from '../ddo/DDO'
|
|||||||
import { SubscribablePromise } from '../utils'
|
import { SubscribablePromise } from '../utils'
|
||||||
import { OrderProgressStep } from './utils/ServiceUtils'
|
import { OrderProgressStep } from './utils/ServiceUtils'
|
||||||
|
|
||||||
export interface ComputeJobStatus {
|
export enum ComputeJobStatus {
|
||||||
|
Started,
|
||||||
|
ConfiguringVolumes,
|
||||||
|
RunningAlgorithm,
|
||||||
|
FilteringResults,
|
||||||
|
PublishingResult,
|
||||||
|
Completed,
|
||||||
|
Stopped,
|
||||||
|
Deleted
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ComputeJob {
|
||||||
owner: string
|
owner: string
|
||||||
agreementId: string
|
agreementId: string
|
||||||
jobId: string
|
jobId: string
|
||||||
dateCreated: string
|
dateCreated: string
|
||||||
dateFinished: string
|
dateFinished: string
|
||||||
status: number
|
status: ComputeJobStatus
|
||||||
statusText: string
|
statusText: string
|
||||||
configlogUrl: string
|
configlogUrl: string
|
||||||
publishlogUrl: string
|
publishlogUrl: string
|
||||||
@ -71,14 +82,14 @@ export class OceanCompute extends Instantiable {
|
|||||||
* @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.
|
||||||
* @return {Promise<ComputeJobStatus>} 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
|
||||||
): Promise<ComputeJobStatus> {
|
): Promise<ComputeJob> {
|
||||||
const status = await this.ocean.brizo.compute(
|
const status = await this.ocean.brizo.compute(
|
||||||
'post',
|
'post',
|
||||||
agreementId,
|
agreementId,
|
||||||
@ -87,7 +98,7 @@ export class OceanCompute extends Instantiable {
|
|||||||
algorithmMeta
|
algorithmMeta
|
||||||
)
|
)
|
||||||
|
|
||||||
return status
|
return status as ComputeJob
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,13 +106,13 @@ export class OceanCompute extends Instantiable {
|
|||||||
* @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} jobId The ID of the compute job to be stopped
|
* @param {string} jobId The ID of the compute job to be stopped
|
||||||
* @return {Promise<ComputeJobStatus>} Returns the new status of a job
|
* @return {Promise<ComputeJob>} Returns the new status of a job
|
||||||
*/
|
*/
|
||||||
public async stop(
|
public async stop(
|
||||||
consumerAccount: Account,
|
consumerAccount: Account,
|
||||||
agreementId: string,
|
agreementId: string,
|
||||||
jobId: string
|
jobId: string
|
||||||
): Promise<ComputeJobStatus> {
|
): Promise<ComputeJob> {
|
||||||
const status = await this.ocean.brizo.compute(
|
const status = await this.ocean.brizo.compute(
|
||||||
'put',
|
'put',
|
||||||
agreementId,
|
agreementId,
|
||||||
@ -109,7 +120,7 @@ export class OceanCompute extends Instantiable {
|
|||||||
jobId
|
jobId
|
||||||
)
|
)
|
||||||
|
|
||||||
return status
|
return status as ComputeJob
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -117,13 +128,13 @@ export class OceanCompute extends Instantiable {
|
|||||||
* @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} jobId The ID of the compute job to be stopped
|
* @param {string} jobId The ID of the compute job to be stopped
|
||||||
* @return {Promise<ComputeJobStatus>} Returns the new status of a job
|
* @return {Promise<ComputeJob>} Returns the new status of a job
|
||||||
*/
|
*/
|
||||||
public async delete(
|
public async delete(
|
||||||
consumerAccount: Account,
|
consumerAccount: Account,
|
||||||
agreementId: string,
|
agreementId: string,
|
||||||
jobId: string
|
jobId: string
|
||||||
): Promise<ComputeJobStatus> {
|
): Promise<ComputeJob> {
|
||||||
const status = await this.ocean.brizo.compute(
|
const status = await this.ocean.brizo.compute(
|
||||||
'delete',
|
'delete',
|
||||||
agreementId,
|
agreementId,
|
||||||
@ -131,7 +142,7 @@ export class OceanCompute extends Instantiable {
|
|||||||
jobId
|
jobId
|
||||||
)
|
)
|
||||||
|
|
||||||
return status
|
return status as ComputeJob
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -139,13 +150,13 @@ export class OceanCompute extends Instantiable {
|
|||||||
* @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} jobId The ID of the compute job to be stopped
|
* @param {string} jobId The ID of the compute job to be stopped
|
||||||
* @return {Promise<ComputeJobStatus>} Returns the new status of a job
|
* @return {Promise<ComputeJob>} Returns the new status of a job
|
||||||
*/
|
*/
|
||||||
public async restart(
|
public async restart(
|
||||||
consumerAccount: Account,
|
consumerAccount: Account,
|
||||||
agreementId: string,
|
agreementId: string,
|
||||||
jobId: string
|
jobId: string
|
||||||
): Promise<ComputeJobStatus> {
|
): Promise<ComputeJob> {
|
||||||
await this.stop(consumerAccount, agreementId, jobId)
|
await this.stop(consumerAccount, agreementId, jobId)
|
||||||
const result = await this.start(consumerAccount, agreementId, jobId)
|
const result = await this.start(consumerAccount, agreementId, jobId)
|
||||||
return result
|
return result
|
||||||
@ -156,13 +167,13 @@ export class OceanCompute extends Instantiable {
|
|||||||
* @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} jobId The ID of the compute job to be stopped
|
* @param {string} jobId The ID of the compute job to be stopped
|
||||||
* @return {Promise<ComputeJobStatus[]>} Returns the status
|
* @return {Promise<ComputeJob[]>} Returns the status
|
||||||
*/
|
*/
|
||||||
public async status(
|
public async status(
|
||||||
consumerAccount: Account,
|
consumerAccount: Account,
|
||||||
agreementId?: string,
|
agreementId?: string,
|
||||||
jobId?: string
|
jobId?: string
|
||||||
): Promise<ComputeJobStatus[]> {
|
): Promise<ComputeJob[]> {
|
||||||
const status = await this.ocean.brizo.compute(
|
const status = await this.ocean.brizo.compute(
|
||||||
'get',
|
'get',
|
||||||
agreementId,
|
agreementId,
|
||||||
@ -170,7 +181,7 @@ export class OceanCompute extends Instantiable {
|
|||||||
jobId
|
jobId
|
||||||
)
|
)
|
||||||
|
|
||||||
return status
|
return status as ComputeJob[]
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,6 +15,7 @@ export * from './ddo/DDO'
|
|||||||
export * from './ddo/MetaData'
|
export * from './ddo/MetaData'
|
||||||
|
|
||||||
export { CreateProgressStep } from './ocean/OceanAssets'
|
export { CreateProgressStep } from './ocean/OceanAssets'
|
||||||
|
export { ComputeJob, ComputeJobStatus } from './ocean/OceanCompute'
|
||||||
export { OrderProgressStep } from './ocean/utils/ServiceUtils'
|
export { OrderProgressStep } from './ocean/utils/ServiceUtils'
|
||||||
export {
|
export {
|
||||||
OceanPlatformTechStatus,
|
OceanPlatformTechStatus,
|
||||||
|
@ -4,7 +4,7 @@ import spies from 'chai-spies'
|
|||||||
import { Ocean } from '../../src/ocean/Ocean'
|
import { Ocean } from '../../src/ocean/Ocean'
|
||||||
import config from '../config'
|
import config from '../config'
|
||||||
import { Account } from '../../src/squid'
|
import { Account } from '../../src/squid'
|
||||||
import { OceanCompute } from '../../src/ocean/OceanCompute'
|
import { OceanCompute, ComputeJobStatus } from '../../src/ocean/OceanCompute'
|
||||||
|
|
||||||
use(spies)
|
use(spies)
|
||||||
|
|
||||||
@ -39,10 +39,12 @@ describe('OceanCompute', () => {
|
|||||||
|
|
||||||
describe('#stop()', () => {
|
describe('#stop()', () => {
|
||||||
it('should stop a job', async () => {
|
it('should stop a job', async () => {
|
||||||
spy.on(ocean.utils.fetch, 'put', () => responsify({ status: 6 }))
|
spy.on(ocean.utils.fetch, 'put', () =>
|
||||||
|
responsify({ status: ComputeJobStatus.Completed })
|
||||||
|
)
|
||||||
|
|
||||||
const response = await compute.stop(account, 'xxx', 'xxx')
|
const response = await compute.stop(account, 'xxx', 'xxx')
|
||||||
assert(response.status === 6)
|
assert(response.status === ComputeJobStatus.Completed)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -58,40 +60,50 @@ describe('OceanCompute', () => {
|
|||||||
|
|
||||||
describe('#delete()', () => {
|
describe('#delete()', () => {
|
||||||
it('should delete a job', async () => {
|
it('should delete a job', async () => {
|
||||||
spy.on(ocean.utils.fetch, 'delete', () => responsify({ status: 8 }))
|
spy.on(ocean.utils.fetch, 'delete', () =>
|
||||||
|
responsify({ status: ComputeJobStatus.Deleted })
|
||||||
|
)
|
||||||
|
|
||||||
const response = await compute.delete(account, 'xxx', 'xxx')
|
const response = await compute.delete(account, 'xxx', 'xxx')
|
||||||
assert(response.status === 8)
|
assert(response.status === ComputeJobStatus.Deleted)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('#status()', () => {
|
describe('#status()', () => {
|
||||||
it('should get the status of one job', async () => {
|
it('should get the status of one job', async () => {
|
||||||
spy.on(ocean.utils.fetch, 'get', () => responsify([{ status: 1 }]))
|
spy.on(ocean.utils.fetch, 'get', () =>
|
||||||
|
responsify([{ status: ComputeJobStatus.Started }])
|
||||||
|
)
|
||||||
|
|
||||||
const response = await compute.status(account, 'xxx', 'xxx')
|
const response = await compute.status(account, 'xxx', 'xxx')
|
||||||
assert(response.length === 1)
|
assert(response.length === 1)
|
||||||
assert(response[0].status === 1)
|
assert(response[0].status === ComputeJobStatus.Started)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should get the status of multiple jobs', async () => {
|
it('should get the status of multiple jobs', async () => {
|
||||||
spy.on(ocean.utils.fetch, 'get', () =>
|
spy.on(ocean.utils.fetch, 'get', () =>
|
||||||
responsify([{ status: 1 }, { status: 1 }])
|
responsify([
|
||||||
|
{ status: ComputeJobStatus.Started },
|
||||||
|
{ status: ComputeJobStatus.Started }
|
||||||
|
])
|
||||||
)
|
)
|
||||||
|
|
||||||
const response = await compute.status(account, 'xxx')
|
const response = await compute.status(account, 'xxx')
|
||||||
assert(response.length === 2)
|
assert(response.length === 2)
|
||||||
assert(response[0].status === 1)
|
assert(response[0].status === ComputeJobStatus.Started)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should get all jobs for one owner', async () => {
|
it('should get all jobs for one owner', async () => {
|
||||||
spy.on(ocean.utils.fetch, 'get', () =>
|
spy.on(ocean.utils.fetch, 'get', () =>
|
||||||
responsify([{ status: 1 }, { status: 1 }])
|
responsify([
|
||||||
|
{ status: ComputeJobStatus.Started },
|
||||||
|
{ status: ComputeJobStatus.Started }
|
||||||
|
])
|
||||||
)
|
)
|
||||||
|
|
||||||
const response = await compute.status(account)
|
const response = await compute.status(account)
|
||||||
assert(response.length === 2)
|
assert(response.length === 2)
|
||||||
assert(response[0].status === 1)
|
assert(response[0].status === ComputeJobStatus.Started)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user