-
Notifications
You must be signed in to change notification settings - Fork 19
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 #934 from golemfactory/feature/JST-928/many-of
Many-of
- Loading branch information
Showing
25 changed files
with
665 additions
and
410 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
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* This example demonstrates how easily lease multiple machines at once. | ||
*/ | ||
|
||
import { DemandSpec, GolemNetwork } from "@golem-sdk/golem-js"; | ||
import { pinoPrettyLogger } from "@golem-sdk/pino-logger"; | ||
|
||
const demand: DemandSpec = { | ||
demand: { | ||
activity: { imageTag: "golem/alpine:latest" }, | ||
}, | ||
market: { | ||
maxAgreements: 1, | ||
rentHours: 0.5, | ||
pricing: { | ||
model: "linear", | ||
maxStartPrice: 0.5, | ||
maxCpuPerHourPrice: 1.0, | ||
maxEnvPerHourPrice: 0.5, | ||
}, | ||
}, | ||
}; | ||
|
||
(async () => { | ||
const glm = new GolemNetwork({ | ||
logger: pinoPrettyLogger({ | ||
level: "info", | ||
}), | ||
}); | ||
|
||
try { | ||
await glm.connect(); | ||
// create a pool that can grow up to 3 leases at the same time | ||
const pool = await glm.manyOf({ | ||
concurrency: 3, | ||
demand, | ||
}); | ||
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("Failed to run the example", err); | ||
} finally { | ||
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
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
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
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.