-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
416 additions
and
164 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* This advanced example demonstrates create an allocation manually and then reuse | ||
* it across multiple market orders. | ||
*/ | ||
import { MarketOrderSpec, GolemNetwork } from "@golem-sdk/golem-js"; | ||
import { pinoPrettyLogger } from "@golem-sdk/pino-logger"; | ||
(async () => { | ||
const glm = new GolemNetwork({ | ||
logger: pinoPrettyLogger({ | ||
level: "info", | ||
}), | ||
}); | ||
|
||
try { | ||
await glm.connect(); | ||
|
||
const allocation = await glm.payment.createAllocation({ | ||
budget: 1, | ||
expirationSec: 3600, | ||
}); | ||
|
||
const firstOrder: MarketOrderSpec = { | ||
demand: { | ||
workload: { imageTag: "golem/alpine:latest" }, | ||
}, | ||
market: { | ||
rentHours: 0.5, | ||
pricing: { | ||
model: "burn-rate", | ||
avgGlmPerHour: 0.5, | ||
}, | ||
}, | ||
payment: { | ||
// You can either pass the allocation object ... | ||
allocation, | ||
}, | ||
}; | ||
const secondOrder: MarketOrderSpec = { | ||
demand: { | ||
workload: { imageTag: "golem/alpine:latest" }, | ||
}, | ||
market: { | ||
rentHours: 0.5, | ||
pricing: { | ||
model: "burn-rate", | ||
avgGlmPerHour: 0.5, | ||
}, | ||
}, | ||
payment: { | ||
// ... or just the allocation ID | ||
allocation: allocation.id, | ||
}, | ||
}; | ||
|
||
const lease1 = await glm.oneOf(firstOrder); | ||
const lease2 = await glm.oneOf(secondOrder); | ||
|
||
await lease1 | ||
.getExeUnit() | ||
.then((exe) => exe.run("echo Running on first lease")) | ||
.then((res) => console.log(res.stdout)); | ||
await lease2 | ||
.getExeUnit() | ||
.then((exe) => exe.run("echo Running on second lease")) | ||
.then((res) => console.log(res.stdout)); | ||
|
||
await lease1.finalize(); | ||
await lease2.finalize(); | ||
await glm.payment.releaseAllocation(allocation); | ||
} 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.