Skip to content

Commit

Permalink
Merge pull request #112 from golemfactory/beta
Browse files Browse the repository at this point in the history
Beta to master
  • Loading branch information
grisha87 authored Dec 8, 2023
2 parents 4e61fd4 + 22685bd commit 75fb850
Show file tree
Hide file tree
Showing 23 changed files with 509 additions and 282 deletions.
4 changes: 2 additions & 2 deletions data/project-templates/js-node-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"application"
],
"dependencies": {
"@golem-sdk/golem-js": "^1.0.0",
"@golem-sdk/golem-js": "^1.0.1",
"dotenv": "^16.3.1"
},
"devDependencies": {
"@golem-sdk/cli": "^2.0.0"
"@golem-sdk/cli": "^2.0.1"
}
}
4 changes: 3 additions & 1 deletion data/project-templates/js-node-esm/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ dotenv.config();

// How much you wish to spend
budget: 0.5,

// How do you want to select market proposals
proposalFilter: ProposalFilters.limitPriceFilter({
start: 0.1,
cpuPerSec: 0.1 / 3600,
Expand All @@ -36,6 +38,6 @@ dotenv.config();
} catch (err) {
console.error("Running the task on Golem failed due to", err);
} finally {
await executor.end();
await executor.shutdown();
}
})();
4 changes: 2 additions & 2 deletions data/project-templates/js-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"application"
],
"dependencies": {
"@golem-sdk/golem-js": "^1.0.0",
"@golem-sdk/golem-js": "^1.0.1",
"dotenv": "^16.3.1"
},
"devDependencies": {
"@golem-sdk/cli": "^2.0.0"
"@golem-sdk/cli": "^2.0.1"
}
}
6 changes: 4 additions & 2 deletions data/project-templates/js-node/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const dotenv = require("dotenv");
const { LogLevel, ProposalFilters, TaskExecutor } = require("@golem-sdk/golem-js");
const { LogLevel, TaskExecutor, ProposalFilters } = require("@golem-sdk/golem-js");

dotenv.config();

Expand All @@ -10,6 +10,8 @@ dotenv.config();

// How much you wish to spend
budget: 0.5,

// How do you want to select market proposals
proposalFilter: ProposalFilters.limitPriceFilter({
start: 0.1,
cpuPerSec: 0.1 / 3600,
Expand All @@ -36,6 +38,6 @@ dotenv.config();
} catch (err) {
console.error("Running the task on Golem failed due to", err);
} finally {
await executor.end();
await executor.shutdown();
}
})();
12 changes: 6 additions & 6 deletions data/project-templates/react-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
"preview": "vite preview"
},
"dependencies": {
"@golem-sdk/golem-js": "^1.0.0",
"@golem-sdk/golem-js": "^1.0.1",
"@golem-sdk/react": "^2.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.39",
"@types/react": "^18.2.42",
"@types/react-dom": "^18.2.17",
"@vitejs/plugin-react": "^4.2.0",
"eslint": "^8.54.0",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.55.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.4",
"vite": "^4.5.0"
"eslint-plugin-react-refresh": "^0.4.5",
"vite": "^4.5.1"
}
}
36 changes: 36 additions & 0 deletions data/project-templates/react-js/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,39 @@
max-width: 32em;
text-align: left;
}

.node-version-check-wrapper {
padding: 5px;
}

.node-version-check-task {
padding: 5px;
}

.node-version-check-task-status {
padding: 5px;
margin: 5px;
font-size: 1.9em;
background-color: #fafafa;
border-radius: 10px;
}

.text-error {
color: red;
}

.text-progress {
color: steelblue;
}

.bg-progress {
background-color: steelblue;
}

.text-success {
color: forestgreen;
}

.bg-success {
background-color: forestgreen;
}
2 changes: 2 additions & 0 deletions data/project-templates/react-js/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import reactLogo from "./assets/react.svg";
import viteLogo from "./assets/vite.svg";
import "./App.css";
import { useYagna } from "@golem-sdk/react";
import { NodeVersionCheck } from "./components/NodeVersionCheck.jsx";

function App() {
const { isConnected } = useYagna();
Expand Down Expand Up @@ -37,6 +38,7 @@ function App() {
<code>{`yagna service run --api-allow-origin='${window.location.origin}'`}</code>
</p>
)}
<div className="card">{isConnected && <NodeVersionCheck />}</div>
<div className="card">
<p>
Edit <code>src/App.jsx</code> and save to test HMR
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { useExecutor } from "@golem-sdk/react";
import { LogLevel, ProposalFilters } from "@golem-sdk/golem-js";
import { NodeVersionCheckTask } from "./NodeVersionCheckTask.jsx";

export function NodeVersionCheck() {
const { executor, initialize, isInitialized, isInitializing, terminate, error } = useExecutor({
// What do you want to run
package: "golem/node:20-alpine",

// How much you wish to spend
budget: 0.5,

// How do you want to select market proposals
proposalFilter: ProposalFilters.limitPriceFilter({
start: 0.1,
cpuPerSec: 0.1 / 3600,
envPerSec: 0.1 / 3600,
}),

// Where you want to spend
payment: {
network: "polygon",
},

// Control the execution of tasks
maxTaskRetries: 0,

// Useful for debugging
logLevel: LogLevel.Info,
taskTimeout: 5 * 60 * 1000,
});

return (
<div className="node-version-check-wrapper">
{error && <div className="text-error">Error: {error.toString()}</div>}
{isInitialized && <NodeVersionCheckTask executor={executor} />}
{isInitializing && <div>Executor is initializing</div>}
{!isInitialized && (
<button onClick={initialize} className="bg-progress">
Initialize executor
</button>
)}
{isInitialized && (
<button onClick={terminate} className="bg-success">
Finish and pay for work
</button>
)}
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useTask } from "@golem-sdk/react";
import PropTypes from "prop-types";

export function NodeVersionCheckTask({ executor }) {
const { isRunning, result, run, error } = useTask(executor);

const getNodeVersionTask = async (ctx) => {
return (await ctx.run("node -v")).stdout?.toString() ?? "No version information";
};

return (
<div className="node-version-check-task">
<button onClick={() => run(getNodeVersionTask)} disabled={isRunning} className="bg-progress">
Check NodeJS version on provider
</button>
<div className="node-version-check-task-status">
{isRunning && <div className="text-progress">Task is running...</div>}
{error && <div className="text-error">Task failed: {error.toString()}</div>}
{result && <div className="text-success">Task result: {result}</div>}
</div>
</div>
);
}

NodeVersionCheckTask.propTypes = {
executor: PropTypes.object,
};
2 changes: 2 additions & 0 deletions data/project-templates/react-js/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ button {
cursor: pointer;
transition: border-color 0.25s;
}

button:hover {
border-color: #646cff;
}

button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
Expand Down
18 changes: 9 additions & 9 deletions data/project-templates/react-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
"preview": "vite preview"
},
"dependencies": {
"@golem-sdk/golem-js": "^1.0.0",
"@golem-sdk/golem-js": "^1.0.1",
"@golem-sdk/react": "^2.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.39",
"@types/react": "^18.2.42",
"@types/react-dom": "^18.2.17",
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"@vitejs/plugin-react": "^4.2.0",
"eslint": "^8.54.0",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.55.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.4",
"typescript": "^5.3.2",
"vite": "^4.5.0"
"eslint-plugin-react-refresh": "^0.4.5",
"typescript": "^5.3.3",
"vite": "^4.5.1"
}
}
36 changes: 36 additions & 0 deletions data/project-templates/react-ts/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,39 @@
max-width: 32em;
text-align: left;
}

.node-version-check-wrapper {
padding: 5px;
}

.node-version-check-task {
padding: 5px;
}

.node-version-check-task-status {
padding: 5px;
margin: 5px;
font-size: 1.9em;
background-color: #fafafa;
border-radius: 10px;
}

.text-error {
color: red;
}

.text-progress {
color: steelblue;
}

.bg-progress {
background-color: steelblue;
}

.text-success {
color: forestgreen;
}

.bg-success {
background-color: forestgreen;
}
2 changes: 2 additions & 0 deletions data/project-templates/react-ts/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import reactLogo from "./assets/react.svg";
import viteLogo from "./assets/vite.svg";
import "./App.css";
import { useYagna } from "@golem-sdk/react";
import { NodeVersionCheck } from "./components/NodeVersionCheck";

function App() {
const { isConnected } = useYagna();
Expand Down Expand Up @@ -37,6 +38,7 @@ function App() {
<code>{`yagna service run --api-allow-origin='${window.location.origin}'`}</code>
</p>
)}
<div className="card">{isConnected && <NodeVersionCheck />}</div>
<div className="card">
<p>
Edit <code>src/App.tsx</code> and save to test HMR
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { useExecutor } from "@golem-sdk/react";
import { LogLevel, ProposalFilters } from "@golem-sdk/golem-js";
import { NodeVersionCheckTask } from "./NodeVersionCheckTask";

export function NodeVersionCheck() {
const { executor, initialize, isInitialized, isInitializing, terminate, error } = useExecutor({
// What do you want to run
package: "golem/node:20-alpine",

// How much you wish to spend
budget: 0.5,

// How do you want to select market proposals
proposalFilter: ProposalFilters.limitPriceFilter({
start: 0.1,
cpuPerSec: 0.1 / 3600,
envPerSec: 0.1 / 3600,
}),

// Where you want to spend
payment: {
network: "polygon",
},

// Control the execution of tasks
maxTaskRetries: 0,

// Useful for debugging
logLevel: LogLevel.Info,
taskTimeout: 5 * 60 * 1000,
});

return (
<div className="node-version-check-wrapper">
{error && <div className="text-error">Error: {error.toString()}</div>}
{isInitialized && executor && <NodeVersionCheckTask executor={executor} />}
{isInitializing && <div>Executor is initializing</div>}
{!isInitialized && (
<button onClick={initialize} className="bg-progress">
Initialize executor
</button>
)}
{isInitialized && (
<button onClick={terminate} className="bg-success">
Finish and pay for work
</button>
)}
</div>
);
}
Loading

0 comments on commit 75fb850

Please sign in to comment.