-
Notifications
You must be signed in to change notification settings - Fork 19
/
events.ts
66 lines (58 loc) · 1.6 KB
/
events.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* This example showcases how users can listen to various events exposed from golem-js
*/
import { GolemNetwork } from "@golem-sdk/golem-js";
import { pinoPrettyLogger } from "@golem-sdk/pino-logger";
(async () => {
const glm = new GolemNetwork({
logger: pinoPrettyLogger({
level: "info",
}),
payment: {
driver: "erc20",
network: "holesky",
},
});
try {
await glm.connect();
glm.market.events.on("agreementApproved", (event) => {
console.log("Agreement '%s' approved", event.agreement.id);
});
glm.market.events.on("agreementTerminated", (event) => {
console.log(
"Agreement '%s' terminated by '%s' with reason '%s'",
event.agreement.id,
event.terminatedBy,
event.reason,
);
});
glm.market.events.on("offerCounterProposalRejected", (event) => {
console.warn("Proposal rejected by provider", event);
});
const rental = await glm.oneOf({
order: {
demand: {
workload: { imageTag: "golem/alpine:latest" },
},
market: {
rentHours: 0.5,
pricing: {
model: "linear",
maxStartPrice: 0.5,
maxCpuPerHourPrice: 1.0,
maxEnvPerHourPrice: 0.5,
},
},
},
});
await rental
.getExeUnit()
.then((exe) => exe.run("echo Hello, Golem! 👋"))
.then((res) => console.log(res.stdout));
await rental.stopAndFinalize();
} catch (err) {
console.error("Failed to run the example", err);
} finally {
await glm.disconnect();
}
})().catch(console.error);