Simple Polymorph Task

A Simple Task that introduces Polymorphs

🚧

Assumptions Ahead

These examples assume you are using the permissive whitelist. If you restrict the whitelist, these examples will need to be modified.

πŸ“˜

Minimum Version Required

These examples assume you are running v14.1.1 or later. Older versions of Computes will not run these examples correctly.

This task will have output similar to the Simple Task, however you will learn how to use IPLD links to reference data. We call these properties Polymorphs. This lets you use pointers to data, instead of having to use the raw data over and over again. If you were to create thousands of tasks that referred to the same taskDefinition it would be easier to manage one source file and a thousand pointers.

This task will simply take an input value and split it into an array of numbers.

1. Copy These Files

{
  "runner": {
    "type": "docker-json-runner",
    "manifest": {
      "*": {
        "image": "computes/fibonacci-sum-split:latest"
      }
    }
  },
  "result": {
    "action": "set",
    "destination": {
      "dataset": { 
        "init": "simple-polymorph-example-results"
      },
      "path": "split/results"
    }
  }
}
{
  "input": {
    "dataset": 2
  },
  "taskDefinition": {
    "/": "<split-polymorph-task-definition-hash-here>"
  },
  "status": {
    "init": "simple-polymorph-example-status"
  }
}

Before we are able to run this task, we'll need to fill in some of those values.

2. Add split-polymorph-task-definition.json to IPFS

cat split-polymorph-task-definition.json | ipfs dag put > split-task-polymorph-definition.hash

3. Edit split-task.json

Replace <split-polymorph-task-definition-hash-here> with the value from split-polymorph-task-definition.hash. This creates the IPFS link to the split-polymorph-task-definition.json from above.

4. Add split-polymorph-task.json to IPFS

Add the task to IPFS so we can enqueue it.

cat split-polymorph-task.json | ipfs dag put > split-polymorph-task.hash

5. Enqueue the Task

Enqueue the task so it can be run by Computes.

cat split-polymorph-task.hash | computes-cli task enqueue

6. Check the results

You may periodically run this command to see if the results are in. In this case we should see some data under split/results and map/results. When the task is complete, you'll see an array of numbers in the results. We'll explain more in Chained Task.

cat split-polymorph-task.hash | computes-cli task dataset

Expected Results:

{
  "split": {
    "results": [
      1,
      2
    ]
  }
}

No response? Check task status for errors

cat split-polymorph-task.hash | computes-cli task status

What’s Next