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 { 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'
|
||||
|
||||
describe('Compute', () => {
|
||||
@ -62,6 +62,6 @@ describe('Compute', () => {
|
||||
it('should start a compute job', async () => {
|
||||
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 { DDO } from '../ddo/DDO'
|
||||
import { ServiceType } from '../ddo/Service'
|
||||
import { ComputeJob } from '../ocean/OceanCompute'
|
||||
|
||||
const apiPath = '/api/v1/brizo/services'
|
||||
|
||||
@ -116,7 +117,7 @@ export class Brizo extends Instantiable {
|
||||
algorithmDid?: string,
|
||||
algorithmMeta?: MetaData,
|
||||
jobId?: string
|
||||
): Promise<any> {
|
||||
): Promise<ComputeJob | ComputeJob[]> {
|
||||
const signature = await this.createSignature(consumerAccount, serviceAgreementId)
|
||||
const address = consumerAccount.getId()
|
||||
const serviceEndpoint = await this.getEndpointFromAgreement(
|
||||
|
@ -5,13 +5,24 @@ import { DDO } from '../ddo/DDO'
|
||||
import { SubscribablePromise } from '../utils'
|
||||
import { OrderProgressStep } from './utils/ServiceUtils'
|
||||
|
||||
export interface ComputeJobStatus {
|
||||
export enum ComputeJobStatus {
|
||||
Started,
|
||||
ConfiguringVolumes,
|
||||
RunningAlgorithm,
|
||||
FilteringResults,
|
||||
PublishingResult,
|
||||
Completed,
|
||||
Stopped,
|
||||
Deleted
|
||||
}
|
||||
|
||||
export interface ComputeJob {
|
||||
owner: string
|
||||
agreementId: string
|
||||
jobId: string
|
||||
dateCreated: string
|
||||
dateFinished: string
|
||||
status: number
|
||||
status: ComputeJobStatus
|
||||
statusText: string
|
||||
configlogUrl: string
|
||||
publishlogUrl: string
|
||||
@ -71,14 +82,14 @@ export class OceanCompute extends Instantiable {
|
||||
* @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.
|
||||
* @return {Promise<ComputeJobStatus>} Returns compute job ID under status.jobId
|
||||
* @return {Promise<ComputeJob>} Returns compute job ID under status.jobId
|
||||
*/
|
||||
public async start(
|
||||
consumerAccount: Account,
|
||||
agreementId: string,
|
||||
algorithmDid?: string,
|
||||
algorithmMeta?: MetaData
|
||||
): Promise<ComputeJobStatus> {
|
||||
): Promise<ComputeJob> {
|
||||
const status = await this.ocean.brizo.compute(
|
||||
'post',
|
||||
agreementId,
|
||||
@ -87,7 +98,7 @@ export class OceanCompute extends Instantiable {
|
||||
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 {string} agreementId The service agreement ID.
|
||||
* @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(
|
||||
consumerAccount: Account,
|
||||
agreementId: string,
|
||||
jobId: string
|
||||
): Promise<ComputeJobStatus> {
|
||||
): Promise<ComputeJob> {
|
||||
const status = await this.ocean.brizo.compute(
|
||||
'put',
|
||||
agreementId,
|
||||
@ -109,7 +120,7 @@ export class OceanCompute extends Instantiable {
|
||||
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 {string} agreementId The service agreement ID.
|
||||
* @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(
|
||||
consumerAccount: Account,
|
||||
agreementId: string,
|
||||
jobId: string
|
||||
): Promise<ComputeJobStatus> {
|
||||
): Promise<ComputeJob> {
|
||||
const status = await this.ocean.brizo.compute(
|
||||
'delete',
|
||||
agreementId,
|
||||
@ -131,7 +142,7 @@ export class OceanCompute extends Instantiable {
|
||||
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 {string} agreementId The service agreement ID.
|
||||
* @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(
|
||||
consumerAccount: Account,
|
||||
agreementId: string,
|
||||
jobId: string
|
||||
): Promise<ComputeJobStatus> {
|
||||
): Promise<ComputeJob> {
|
||||
await this.stop(consumerAccount, agreementId, jobId)
|
||||
const result = await this.start(consumerAccount, agreementId, jobId)
|
||||
return result
|
||||
@ -156,13 +167,13 @@ export class OceanCompute extends Instantiable {
|
||||
* @param {Account} consumerAccount The account of the consumer ordering the service.
|
||||
* @param {string} agreementId The service agreement ID.
|
||||
* @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(
|
||||
consumerAccount: Account,
|
||||
agreementId?: string,
|
||||
jobId?: string
|
||||
): Promise<ComputeJobStatus[]> {
|
||||
): Promise<ComputeJob[]> {
|
||||
const status = await this.ocean.brizo.compute(
|
||||
'get',
|
||||
agreementId,
|
||||
@ -170,7 +181,7 @@ export class OceanCompute extends Instantiable {
|
||||
jobId
|
||||
)
|
||||
|
||||
return status
|
||||
return status as ComputeJob[]
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -15,6 +15,7 @@ export * from './ddo/DDO'
|
||||
export * from './ddo/MetaData'
|
||||
|
||||
export { CreateProgressStep } from './ocean/OceanAssets'
|
||||
export { ComputeJob, ComputeJobStatus } from './ocean/OceanCompute'
|
||||
export { OrderProgressStep } from './ocean/utils/ServiceUtils'
|
||||
export {
|
||||
OceanPlatformTechStatus,
|
||||
|
@ -4,7 +4,7 @@ import spies from 'chai-spies'
|
||||
import { Ocean } from '../../src/ocean/Ocean'
|
||||
import config from '../config'
|
||||
import { Account } from '../../src/squid'
|
||||
import { OceanCompute } from '../../src/ocean/OceanCompute'
|
||||
import { OceanCompute, ComputeJobStatus } from '../../src/ocean/OceanCompute'
|
||||
|
||||
use(spies)
|
||||
|
||||
@ -39,10 +39,12 @@ describe('OceanCompute', () => {
|
||||
|
||||
describe('#stop()', () => {
|
||||
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')
|
||||
assert(response.status === 6)
|
||||
assert(response.status === ComputeJobStatus.Completed)
|
||||
})
|
||||
})
|
||||
|
||||
@ -58,40 +60,50 @@ describe('OceanCompute', () => {
|
||||
|
||||
describe('#delete()', () => {
|
||||
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')
|
||||
assert(response.status === 8)
|
||||
assert(response.status === ComputeJobStatus.Deleted)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#status()', () => {
|
||||
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')
|
||||
assert(response.length === 1)
|
||||
assert(response[0].status === 1)
|
||||
assert(response[0].status === ComputeJobStatus.Started)
|
||||
})
|
||||
|
||||
it('should get the status of multiple jobs', async () => {
|
||||
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')
|
||||
assert(response.length === 2)
|
||||
assert(response[0].status === 1)
|
||||
assert(response[0].status === ComputeJobStatus.Started)
|
||||
})
|
||||
|
||||
it('should get all jobs for one owner', async () => {
|
||||
spy.on(ocean.utils.fetch, 'get', () =>
|
||||
responsify([{ status: 1 }, { status: 1 }])
|
||||
responsify([
|
||||
{ status: ComputeJobStatus.Started },
|
||||
{ status: ComputeJobStatus.Started }
|
||||
])
|
||||
)
|
||||
|
||||
const response = await compute.status(account)
|
||||
assert(response.length === 2)
|
||||
assert(response[0].status === 1)
|
||||
assert(response[0].status === ComputeJobStatus.Started)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user