-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #211 from golemfactory/feature/JST-889/update-gole…
…m-js-to-3.0-in-cli Update golem-js to 3.0
- Loading branch information
Showing
23 changed files
with
653 additions
and
528 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.