Skip to content

Commit

Permalink
Merge pull request #226 from golemfactory/beta
Browse files Browse the repository at this point in the history
Beta -> master (react templates)
  • Loading branch information
grisha87 authored Jul 25, 2024
2 parents 75c5281 + 7334f34 commit 51abe00
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 222 deletions.
5 changes: 3 additions & 2 deletions data/project-templates/react-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
"preview": "vite preview"
},
"dependencies": {
"@golem-sdk/golem-js": "^3.0.0",
"@golem-sdk/react": "^3.0.1",
"@golem-sdk/golem-js": "^3.1.0",
"@golem-sdk/react": "^4.0.0",
"@golem-sdk/task-executor": "^2.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
45 changes: 24 additions & 21 deletions data/project-templates/react-js/src/components/NodeVersionCheck.jsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
import { useExecutor } from "@golem-sdk/react";
import { ProposalFilterFactory } from "@golem-sdk/golem-js";
import { NodeVersionCheckTask } from "./NodeVersionCheckTask.jsx";
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: 2,

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

demand: {
workload: {
imageTag: "golem/node:20-alpine",
},
},
// Where you want to spend
payment: {
network: "goerli",
network: "holesky",
},
market: {
// Let's rent the provider for no more than 15 minutes
rentHours: 15 / 60,
// Let's agree to pay at most 0.5 GLM per hour
pricing: {
model: "burn-rate",
avgGlmPerHour: 0.5,
},
},

// Control the execution of tasks
maxTaskRetries: 0,
taskTimeout: 5 * 60 * 1000,
task: {
taskTimeout: 5 * 60 * 1000,
maxTaskRetries: 0,
},
// Look at the browser console to see what's happening under the hood
enableLogging: true,
});

return (
<div className="node-version-check-wrapper">
{error && <div className="text-error">Error: {error.toString()}</div>}
{isInitialized && <NodeVersionCheckTask executor={executor} />}
{isInitialized && executor && <NodeVersionCheckTask executor={executor} />}
{isInitializing && <div>Executor is initializing</div>}
{!isInitialized && (
<button onClick={initialize} className="bg-progress">
<button onClick={() => initialize()} className="bg-progress">
Initialize executor
</button>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ 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";
const getNodeVersionTask = async (exe) => {
return (await exe.run("node -v")).stdout?.toString() ?? "No version information";
};

return (
Expand Down
5 changes: 3 additions & 2 deletions data/project-templates/react-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
"preview": "vite preview"
},
"dependencies": {
"@golem-sdk/golem-js": "^3.0.0",
"@golem-sdk/react": "^3.0.1",
"@golem-sdk/golem-js": "^3.1.0",
"@golem-sdk/react": "^4.0.0",
"@golem-sdk/task-executor": "^2.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
41 changes: 22 additions & 19 deletions data/project-templates/react-ts/src/components/NodeVersionCheck.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
import { useExecutor } from "@golem-sdk/react";
import { ProposalFilterFactory } 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: 2,

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

demand: {
workload: {
imageTag: "golem/node:20-alpine",
},
},
// Where you want to spend
payment: {
network: "goerli",
network: "holesky",
},
market: {
// Let's rent the provider for no more than 15 minutes
rentHours: 15 / 60,
// Let's agree to pay at most 0.5 GLM per hour
pricing: {
model: "burn-rate",
avgGlmPerHour: 0.5,
},
},

// Control the execution of tasks
maxTaskRetries: 0,
taskTimeout: 5 * 60 * 1000,
task: {
taskTimeout: 5 * 60 * 1000,
maxTaskRetries: 0,
},
// Look at the browser console to see what's happening under the hood
enableLogging: true,
});

return (
Expand All @@ -33,7 +36,7 @@ export function NodeVersionCheck() {
{isInitialized && executor && <NodeVersionCheckTask executor={executor} />}
{isInitializing && <div>Executor is initializing</div>}
{!isInitialized && (
<button onClick={initialize} className="bg-progress">
<button onClick={() => initialize()} className="bg-progress">
Initialize executor
</button>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { TaskExecutor, useTask, Worker } from "@golem-sdk/react";

import { useTask } from "@golem-sdk/react";
import type { TaskFunction, TaskExecutor } from "@golem-sdk/task-executor";
export function NodeVersionCheckTask({ executor }: { executor: TaskExecutor }) {
const { isRunning, result, run, error } = useTask<string>(executor);

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

return (
Expand Down
Loading

0 comments on commit 51abe00

Please sign in to comment.