Skip to content

Commit

Permalink
Merge pull request #211 from golemfactory/feature/JST-889/update-gole…
Browse files Browse the repository at this point in the history
…m-js-to-3.0-in-cli

Update golem-js to 3.0
  • Loading branch information
SewerynKras authored Jun 13, 2024
2 parents 5bef681 + b64af94 commit a8197d1
Show file tree
Hide file tree
Showing 23 changed files with 653 additions and 528 deletions.
6 changes: 1 addition & 5 deletions data/project-templates/js-node-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
"application"
],
"dependencies": {
"@golem-sdk/golem-js": "^2.2.0",
"@golem-sdk/task-executor": "^1.0.1",
"@golem-sdk/golem-js": "^3.0.0-beta.44",
"dotenv": "^16.4.5"
},
"devDependencies": {
"@golem-sdk/cli": "^2.5.0"
}
}
85 changes: 48 additions & 37 deletions data/project-templates/js-node-esm/src/index.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,55 @@
import * as dotenv from "dotenv";
import { ProposalFilterFactory, TaskExecutor } from "@golem-sdk/task-executor";
import { pinoLogger } from "@golem-sdk/golem-js";

dotenv.config();

(async function main() {
const executor = await TaskExecutor.create({
// 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,
}),

// Where you want to spend
payment: {
network: "goerli",
import "dotenv/config";
import { GolemNetwork } from "@golem-sdk/golem-js";

const order = {
demand: {
workload: { imageTag: "golem/alpine:latest" },
},
market: {
// 5 minutes
rentHours: 5 / 60,
pricing: {
model: "linear",
maxStartPrice: 0.5,
maxCpuPerHourPrice: 1.0,
maxEnvPerHourPrice: 0.5,
},
},
};

// Control the execution of tasks
maxTaskRetries: 0,

// Useful for debugging
logger: pinoLogger({ level: "info" }),
taskTimeout: 5 * 60 * 1000,
});
(async () => {
const glm = new GolemNetwork();

try {
// Your code goes here
const result = await executor.run((ctx) => ctx.run("node -v"));
console.log("Version of NodeJS on Provider:", result.stdout.trim());
await glm.connect();
// create a pool that can grow up to 3 leases at the same time
const pool = await glm.manyOf({
concurrency: 3,
order,
});
await Promise.allSettled([
pool.withLease(async (lease) =>
lease
.getExeUnit()
.then((exe) => exe.run("echo Hello, Golem from the first machine! 👋"))
.then((res) => console.log(res.stdout)),
),
pool.withLease(async (lease) =>
lease
.getExeUnit()
.then((exe) => exe.run("echo Hello, Golem from the second machine! 👋"))
.then((res) => console.log(res.stdout)),
),
pool.withLease(async (lease) =>
lease
.getExeUnit()
.then((exe) => exe.run("echo Hello, Golem from the third machine! 👋"))
.then((res) => console.log(res.stdout)),
),
]);
} catch (err) {
console.error("Running the task on Golem failed due to", err);
console.error("Something went wrong:", err);
} finally {
await executor.shutdown();
await glm.disconnect();
}
})();
})().catch(console.error);
6 changes: 1 addition & 5 deletions data/project-templates/js-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
"application"
],
"dependencies": {
"@golem-sdk/golem-js": "^2.2.0",
"@golem-sdk/task-executor": "^1.0.1",
"@golem-sdk/golem-js": "^3.0.0-beta.44",
"dotenv": "^16.4.5"
},
"devDependencies": {
"@golem-sdk/cli": "^2.5.0"
}
}
85 changes: 48 additions & 37 deletions data/project-templates/js-node/src/index.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,55 @@
const dotenv = require("dotenv");
const { TaskExecutor, ProposalFilterFactory } = require("@golem-sdk/task-executor");
const { pinoLogger } = require("@golem-sdk/golem-js");

dotenv.config();

(async function main() {
const executor = await TaskExecutor.create({
// 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,
}),

// Where you want to spend
payment: {
network: "goerli",
require("dotenv").config();
const { GolemNetwork } = require("@golem-sdk/golem-js");

const order = {
demand: {
workload: { imageTag: "golem/alpine:latest" },
},
market: {
// 5 minutes
rentHours: 5 / 60,
pricing: {
model: "linear",
maxStartPrice: 0.5,
maxCpuPerHourPrice: 1.0,
maxEnvPerHourPrice: 0.5,
},
},
};

// Control the execution of tasks
maxTaskRetries: 0,

// Useful for debugging
logger: pinoLogger({ level: "info" }),
taskTimeout: 5 * 60 * 1000,
});
(async () => {
const glm = new GolemNetwork();

try {
// Your code goes here
const result = await executor.run((ctx) => ctx.run("node -v"));
console.log("Version of NodeJS on Provider:", result.stdout.trim());
await glm.connect();
// create a pool that can grow up to 3 leases at the same time
const pool = await glm.manyOf({
concurrency: 3,
order,
});
await Promise.allSettled([
pool.withLease(async (lease) =>
lease
.getExeUnit()
.then((exe) => exe.run("echo Hello, Golem from the first machine! 👋"))
.then((res) => console.log(res.stdout)),
),
pool.withLease(async (lease) =>
lease
.getExeUnit()
.then((exe) => exe.run("echo Hello, Golem from the second machine! 👋"))
.then((res) => console.log(res.stdout)),
),
pool.withLease(async (lease) =>
lease
.getExeUnit()
.then((exe) => exe.run("echo Hello, Golem from the third machine! 👋"))
.then((res) => console.log(res.stdout)),
),
]);
} catch (err) {
console.error("Running the task on Golem failed due to", err);
console.error("Something went wrong:", err);
} finally {
await executor.shutdown();
await glm.disconnect();
}
})();
})().catch(console.error);
2 changes: 1 addition & 1 deletion data/project-templates/react-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"preview": "vite preview"
},
"dependencies": {
"@golem-sdk/golem-js": "^2.2.0",
"@golem-sdk/golem-js": "^3.0.0-beta.44",
"@golem-sdk/react": "^3.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand Down
2 changes: 1 addition & 1 deletion data/project-templates/react-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"preview": "vite preview"
},
"dependencies": {
"@golem-sdk/golem-js": "^2.2.0",
"@golem-sdk/golem-js": "^3.0.0-beta.44",
"@golem-sdk/react": "^3.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand Down
6 changes: 1 addition & 5 deletions data/project-templates/ts-node-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
"application"
],
"dependencies": {
"@golem-sdk/golem-js": "^2.2.0",
"@golem-sdk/task-executor": "^1.0.1",
"@golem-sdk/golem-js": "^3.0.0-beta.44",
"dotenv": "^16.4.5"
},
"devDependencies": {
"@golem-sdk/cli": "^2.5.0"
}
}
87 changes: 48 additions & 39 deletions data/project-templates/ts-node-esm/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,55 @@
import * as dotenv from "dotenv";
import { ProposalFilterFactory, TaskExecutor } from "@golem-sdk/task-executor";
import { pinoLogger } from "@golem-sdk/golem-js";

dotenv.config();

(async function main() {
const executor = await TaskExecutor.create({
// 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,
}),

// Where you want to spend
payment: {
network: "goerli",
import "dotenv/config";
import { GolemNetwork, MarketOrderSpec } from "@golem-sdk/golem-js";

const order: MarketOrderSpec = {
demand: {
workload: { imageTag: "golem/alpine:latest" },
},
market: {
// 5 minutes
rentHours: 5 / 60,
pricing: {
model: "linear",
maxStartPrice: 0.5,
maxCpuPerHourPrice: 1.0,
maxEnvPerHourPrice: 0.5,
},
},
};

// Control the execution of tasks
maxTaskRetries: 0,

// Useful for debugging
logger: pinoLogger({
level: "info",
}),
taskTimeout: 5 * 60 * 1000,
});
(async () => {
const glm = new GolemNetwork();

try {
// Your code goes here
const result = await executor.run((ctx) => ctx.run("node -v"));
console.log("Version of NodeJS on Provider:", (result!.stdout as string).trim());
await glm.connect();
// create a pool that can grow up to 3 leases at the same time
const pool = await glm.manyOf({
concurrency: 3,
order,
});
await Promise.allSettled([
pool.withLease(async (lease) =>
lease
.getExeUnit()
.then((exe) => exe.run("echo Hello, Golem from the first machine! 👋"))
.then((res) => console.log(res.stdout)),
),
pool.withLease(async (lease) =>
lease
.getExeUnit()
.then((exe) => exe.run("echo Hello, Golem from the second machine! 👋"))
.then((res) => console.log(res.stdout)),
),
pool.withLease(async (lease) =>
lease
.getExeUnit()
.then((exe) => exe.run("echo Hello, Golem from the third machine! 👋"))
.then((res) => console.log(res.stdout)),
),
]);
} catch (err) {
console.error("Running the task on Golem failed due to", err);
console.error("Something went wrong:", err);
} finally {
await executor.shutdown();
await glm.disconnect();
}
})();
})().catch(console.error);
6 changes: 1 addition & 5 deletions data/project-templates/ts-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
"application"
],
"dependencies": {
"@golem-sdk/golem-js": "^2.2.0",
"@golem-sdk/task-executor": "^1.0.1",
"@golem-sdk/golem-js": "^3.0.0-beta.44",
"dotenv": "^16.4.5"
},
"devDependencies": {
"@golem-sdk/cli": "^2.5.0"
}
}
Loading

0 comments on commit a8197d1

Please sign in to comment.