Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions lib/blueprint-job-code.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export const blueprintJobCode = {
square: `use blueprint_sdk::macros::debug_job;
use blueprint_sdk::tangle::extract::{TangleArg, TangleResult};

#[debug_job]
pub async fn square(TangleArg((x,)): TangleArg<(u64,)>) -> TangleResult<u64> {
let result = x * x;
TangleResult(result)
}`,
router: `use blueprint_sdk::macros::debug_job;
use blueprint_sdk::tangle::extract::{TangleArg, TangleResult};
use blueprint_sdk::tangle::TangleLayer;
use blueprint_sdk::{Job, Router};

pub const XSQUARE_JOB_ID: u8 = 0;

#[debug_job]
pub async fn square(TangleArg((x,)): TangleArg<(u64,)>) -> TangleResult<u64> {
let result = x * x;
TangleResult(result)
}

#[must_use]
pub fn router() -> Router {
Router::new().route(XSQUARE_JOB_ID, square.layer(TangleLayer))
}`,
};
29 changes: 16 additions & 13 deletions pages/developers/blueprint-runner/jobs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
title: Jobs
---

import GithubFileReaderDisplay from '/components/GithubFileReaderDisplay';
import CodeDisplay from '/components/CodeDisplay';
import { blueprintJobCode } from '/lib/blueprint-job-code';

# Jobs

Expand All @@ -29,18 +30,18 @@ Jobs in a Blueprint are defined in the library package of your project. A job de

### Basic Job Structure

This source excerpt defines `square` in the Incredible Squaring example.
Run it as part of that example project.
A squaring handler with its imports, for `src/lib.rs` in a Blueprint project:

<GithubFileReaderDisplay
url="https://github.com/tangle-network/blueprint/blob/9acf12127c9ef89b9ffcfb95dd5371dca4326531/examples/incredible-squaring/incredible-squaring-lib/src/lib.rs"
fromLine={83}
toLine={87}
<CodeDisplay
language="rust"
title="lib.rs"
sourceUrl="https://github.com/tangle-network/blueprint/blob/9acf12127c9ef89b9ffcfb95dd5371dca4326531/examples/incredible-squaring/incredible-squaring-lib/src/lib.rs#L25-L87"
code={blueprintJobCode.square}
/>

In this example:

- The router registers `square` under the `XSQUARE_JOB_ID` constant
- The router below registers `square` under the `XSQUARE_JOB_ID` constant
- `square` is the function that implements the job's logic
- The job takes a single ABI-encoded input parameter `x` extracted by `TangleArg<(u64,)>`
- The job returns a `TangleResult<u64>`, which the runner ABI-encodes for submission
Expand All @@ -60,12 +61,14 @@ See the [Contexts guide](/developers/contexts/introduction) for complete example

## Job Registration

Jobs need to be registered to a route with the [router](/developers/blueprint-runner/routers) to be accessible. This is done when defining a Blueprint Runner:
Register the handler with the [router](/developers/blueprint-runner/routers).
This complete `src/lib.rs` registers the squaring job on the Tangle layer:

<GithubFileReaderDisplay
url="https://github.com/tangle-network/blueprint/blob/9acf12127c9ef89b9ffcfb95dd5371dca4326531/examples/incredible-squaring/incredible-squaring-lib/src/lib.rs"
fromLine={201}
toLine={217}
<CodeDisplay
language="rust"
title="lib.rs"
sourceUrl="https://github.com/tangle-network/blueprint/blob/9acf12127c9ef89b9ffcfb95dd5371dca4326531/examples/incredible-squaring/incredible-squaring-lib/src/lib.rs#L201-L217"
code={blueprintJobCode.router}
/>

## Job Execution Flow
Expand Down
14 changes: 14 additions & 0 deletions review-evidence/docs-jobs-20261002/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Jobs code examples

Before: https://docs.tangle.tools/developers/blueprint-runner/jobs, served shared CodeDisplay from Docs #190.
After: real Next dev preview of the changed Jobs page, based on `31a50b6`.
Viewports: 1440 × 1000 and 390 × 1000; light and dark themes.

The copy recording runs at normal speed; the MP4 is a format conversion of the retained WebM original.
`proof.json` records exact clipboard text, keyboard focus and code scrolling, and document width.
Both snippets contain their own imports and definitions and preserve indentation.
Imports, handler, job constant and route were checked against SDK commit `9acf12127c9ef89b9ffcfb95dd5371dca4326531`.
The router example keeps that source's single `square` route.
The rendered page and source links were checked; a separate Cargo compilation was not run.

These review artifacts are outside the documentation's application and public directories.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added review-evidence/docs-jobs-20261002/before-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
104 changes: 104 additions & 0 deletions review-evidence/docs-jobs-20261002/proof.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
[
{
"width": 1440,
"theme": "light",
"sections": [
{
"i": 0,
"copied": "use blueprint_sdk::macros::debug_job;\nuse blueprint_sdk::tangle::extract::{TangleArg, TangleResult};\n\n#[debug_job]\npub async fn square(TangleArg((x,)): TangleArg<(u64,)>) -> TangleResult<u64> {\n let result = x * x;\n TangleResult(result)\n}",
"source": "https://github.com/tangle-network/blueprint/blob/9acf12127c9ef89b9ffcfb95dd5371dca4326531/examples/incredible-squaring/incredible-squaring-lib/src/lib.rs#L25-L87",
"copiedFeedback": "Copied",
"focus": true,
"scroll": {
"width": 830,
"overflow": 830,
"left": 0
}
},
{
"i": 1,
"copied": "use blueprint_sdk::macros::debug_job;\nuse blueprint_sdk::tangle::extract::{TangleArg, TangleResult};\nuse blueprint_sdk::tangle::TangleLayer;\nuse blueprint_sdk::{Job, Router};\n\npub const XSQUARE_JOB_ID: u8 = 0;\n\n#[debug_job]\npub async fn square(TangleArg((x,)): TangleArg<(u64,)>) -> TangleResult<u64> {\n let result = x * x;\n TangleResult(result)\n}\n\n#[must_use]\npub fn router() -> Router {\n Router::new().route(XSQUARE_JOB_ID, square.layer(TangleLayer))\n}",
"source": "https://github.com/tangle-network/blueprint/blob/9acf12127c9ef89b9ffcfb95dd5371dca4326531/examples/incredible-squaring/incredible-squaring-lib/src/lib.rs#L201-L217",
"copiedFeedback": "Copied",
"focus": true,
"scroll": {
"width": 830,
"overflow": 830,
"left": 0
}
}
],
"widthState": {
"client": 1440,
"scroll": 1440
}
},
{
"width": 390,
"theme": "light",
"sections": [
{
"i": 0,
"copied": "use blueprint_sdk::macros::debug_job;\nuse blueprint_sdk::tangle::extract::{TangleArg, TangleResult};\n\n#[debug_job]\npub async fn square(TangleArg((x,)): TangleArg<(u64,)>) -> TangleResult<u64> {\n let result = x * x;\n TangleResult(result)\n}",
"source": "https://github.com/tangle-network/blueprint/blob/9acf12127c9ef89b9ffcfb95dd5371dca4326531/examples/incredible-squaring/incredible-squaring-lib/src/lib.rs#L25-L87",
"copiedFeedback": "Copied",
"focus": true,
"scroll": {
"width": 340,
"overflow": 730,
"left": 4
}
},
{
"i": 1,
"copied": "use blueprint_sdk::macros::debug_job;\nuse blueprint_sdk::tangle::extract::{TangleArg, TangleResult};\nuse blueprint_sdk::tangle::TangleLayer;\nuse blueprint_sdk::{Job, Router};\n\npub const XSQUARE_JOB_ID: u8 = 0;\n\n#[debug_job]\npub async fn square(TangleArg((x,)): TangleArg<(u64,)>) -> TangleResult<u64> {\n let result = x * x;\n TangleResult(result)\n}\n\n#[must_use]\npub fn router() -> Router {\n Router::new().route(XSQUARE_JOB_ID, square.layer(TangleLayer))\n}",
"source": "https://github.com/tangle-network/blueprint/blob/9acf12127c9ef89b9ffcfb95dd5371dca4326531/examples/incredible-squaring/incredible-squaring-lib/src/lib.rs#L201-L217",
"copiedFeedback": "Copied",
"focus": true,
"scroll": {
"width": 340,
"overflow": 730,
"left": 40
}
}
],
"widthState": {
"client": 390,
"scroll": 390
}
},
{
"width": 390,
"theme": "dark",
"sections": [
{
"i": 0,
"copied": "use blueprint_sdk::macros::debug_job;\nuse blueprint_sdk::tangle::extract::{TangleArg, TangleResult};\n\n#[debug_job]\npub async fn square(TangleArg((x,)): TangleArg<(u64,)>) -> TangleResult<u64> {\n let result = x * x;\n TangleResult(result)\n}",
"source": "https://github.com/tangle-network/blueprint/blob/9acf12127c9ef89b9ffcfb95dd5371dca4326531/examples/incredible-squaring/incredible-squaring-lib/src/lib.rs#L25-L87",
"copiedFeedback": "Copied",
"focus": true,
"scroll": {
"width": 340,
"overflow": 730,
"left": 1
}
},
{
"i": 1,
"copied": "use blueprint_sdk::macros::debug_job;\nuse blueprint_sdk::tangle::extract::{TangleArg, TangleResult};\nuse blueprint_sdk::tangle::TangleLayer;\nuse blueprint_sdk::{Job, Router};\n\npub const XSQUARE_JOB_ID: u8 = 0;\n\n#[debug_job]\npub async fn square(TangleArg((x,)): TangleArg<(u64,)>) -> TangleResult<u64> {\n let result = x * x;\n TangleResult(result)\n}\n\n#[must_use]\npub fn router() -> Router {\n Router::new().route(XSQUARE_JOB_ID, square.layer(TangleLayer))\n}",
"source": "https://github.com/tangle-network/blueprint/blob/9acf12127c9ef89b9ffcfb95dd5371dca4326531/examples/incredible-squaring/incredible-squaring-lib/src/lib.rs#L201-L217",
"copiedFeedback": "Copied",
"focus": true,
"scroll": {
"width": 340,
"overflow": 730,
"left": 1
}
}
],
"widthState": {
"client": 390,
"scroll": 390
}
}
]