Get Status of a Compute Job

Get Status of a Compute Job

Requirements

For this setup, we need a compute job that has been started from Compute using a published algorithm on a Data Set or Compute using a raw algorithm on a Data Set

Create an Area to display the status

First, let’s define an area to display status:

      <ComputeSection>
        <h3>4. Get Compute Job Status</h3>

        <pre
          id="jobStatus"
          style={{ padding: '1rem', background: 'ghostwhite' }}
        >
          <code>{jobStatus}</code>
        </pre>

        <button onClick={getStatus} disabled={!jobId}>
          Get Job Status
        </button>
      </ComputeSection>

Get Job Status

Since we have the agreementId and jobId, we can get status from a compute job:

      const status = await ocean.compute.status(accounts[0], agreementId, jobId)

Final Result

Let’s wrap that into a function:

  async function getStatus() {
    try {
      const accounts = await ocean.accounts.list()

      const status = await ocean.compute.status(accounts[0], agreementId, jobId)
      setJobStatus(JSON.stringify(status, null, '\t'))
      console.log(status)
    } catch (error) {
      console.error(error.message)
    }
  }

and have a button for it:

        <button onClick={getStatus} disabled={!jobId}>

** Notice that the button will be disabled if jobId is missing.