Skip to content

Commit

Permalink
feat: add compute stop (#72)
Browse files Browse the repository at this point in the history
* feat: add compute stop

* refactor: use stopCompute instead of computeStop
  • Loading branch information
moritzkirstein authored Mar 15, 2024
1 parent ee97319 commit 55956a1
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 9 deletions.
7 changes: 7 additions & 0 deletions src/@types/Compute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ export interface ComputeResultConfig extends ComputeStatusConfig {
resultIndex?: number
}

export interface StopComputeConfig {
did: string
jobId: string
providerUri: string
signer: Signer
}

export interface TokenInfo {
address: string
name: string
Expand Down
22 changes: 15 additions & 7 deletions src/Nautilus/Nautilus.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TransactionReceipt } from '@ethersproject/abstract-provider'
import {
Asset,
Config,
Expand All @@ -14,22 +15,22 @@ import {
ComputeStatusConfig,
CreateAssetConfig,
LifecycleStates,
PublishResponse
PublishResponse,
StopComputeConfig
} from '../@types'
import { access } from '../access'
import { compute, getStatus, retrieveResult, stopCompute } from '../compute'
import {
createAsset,
createServiceWithDatatokenAndPricing,
publishDDO
} from '../publish'
import { getAllPromisesOnArray } from '../utils'
import { NautilusAsset } from './Asset/NautilusAsset'
import { access } from '../access'
import { compute, getStatus, retrieveResult } from '../compute'
import { FileTypes, NautilusService, ServiceTypes } from './Asset'
import { TransactionReceipt } from '@ethersproject/abstract-provider'
import { resolvePublisherTrustedAlgorithms } from '../utils/helpers/trusted-algorithms'
import { getAsset, getAssets } from '../utils/aquarius'
import { editPrice } from '../utils/contracts'
import { resolvePublisherTrustedAlgorithms } from '../utils/helpers/trusted-algorithms'
import { FileTypes, NautilusService, ServiceTypes } from './Asset'
import { NautilusAsset } from './Asset/NautilusAsset'

export { LogLevel } from '@oceanprotocol/lib'

Expand Down Expand Up @@ -345,5 +346,12 @@ export class Nautilus {
signer: this.signer
})
}

async stopCompute(stopComputeConfig: Omit<StopComputeConfig, 'signer'>) {
return await stopCompute({
...stopComputeConfig,
signer: this.signer
})
}
// #endregion
}
12 changes: 10 additions & 2 deletions src/compute/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
ComputeConfig,
ComputeResultConfig,
ComputeStatusConfig,
OrderPriceAndFees
OrderPriceAndFees,
StopComputeConfig
} from '../@types/Compute'
import { getDatatokenBalance, getServiceByName } from '../utils'
import {
Expand All @@ -26,7 +27,8 @@ import { isOrderable, order, reuseOrder } from '../utils/order'
import {
approveProviderFee,
initializeProviderForCompute,
startComputeJob
startComputeJob,
stopComputeJob
} from '../utils/provider'

export async function compute(computeConfig: ComputeConfig) {
Expand Down Expand Up @@ -403,3 +405,9 @@ export async function handleComputeOrder(
LoggerInstance.error(`[compute] ${error.message}`)
}
}

export async function stopCompute(stopComputeConfig: StopComputeConfig) {
const { did, jobId, providerUri, signer } = stopComputeConfig

return await stopComputeJob(providerUri, did, jobId, signer)
}
20 changes: 20 additions & 0 deletions src/utils/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,26 @@ export async function startComputeJob(
}
}

export async function stopComputeJob(
providerUri: string,
did: string,
jobId: string,
signer: Signer
): Promise<ComputeJob | ComputeJob[]> {
try {
return await ProviderInstance.computeStop(
did,
await signer.getAddress(),
jobId,
providerUri,
signer
)
} catch (error) {
LoggerInstance.error('Error stopping compute job!')
LoggerInstance.error(error)
}
}

export function getValidUntilTime(
computeEnvMaxJobDuration: number,
datasetTimeout?: number,
Expand Down

0 comments on commit 55956a1

Please sign in to comment.