Skip to content

Commit

Permalink
build: fixed examples that were breaking the release build pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
grisha87 committed Apr 18, 2024
1 parent a61115b commit 2e2da8b
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 69 deletions.
5 changes: 4 additions & 1 deletion examples/basic/hello-world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import {
} from "@golem-sdk/golem-js";

(async () => {
const yagnaApi = new YagnaApi();

try {
const yagnaApi = new YagnaApi();
await yagnaApi.connect();
const modules = {
market: new MarketModuleImpl(yagnaApi),
Expand Down Expand Up @@ -51,5 +52,7 @@ import {
proposalSubscription.cancel();
} catch (err) {
console.error("Failed to run example on Golem", err);
} finally {
await yagnaApi.disconnect();
}
})().catch(console.error);
138 changes: 71 additions & 67 deletions examples/deployment/new-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,85 +11,89 @@ async function main() {
dataTransferProtocol: "gftp",
});

await golem.connect();
try {
await golem.connect();

const builder = golem.creteDeploymentBuilder();
const builder = golem.creteDeploymentBuilder();

builder
.createNetwork("basic", {
networkOwnerId: "test",
})
.createActivityPool("app", {
demand: {
image: "file://golem/node:20",
// image: "golem/node:20",
// image: "http://golem.io/node:20",
// imageHash: "0x30984084039480493840",
resources: {
minCpu: 4,
minMemGib: 8,
minStorageGib: 16,
builder
.createNetwork("basic", {
networkOwnerId: "test",
})
.createActivityPool("app", {
demand: {
image: "file://golem/node:20",
// image: "golem/node:20",
// image: "http://golem.io/node:20",
// imageHash: "0x30984084039480493840",
resources: {
minCpu: 4,
minMemGib: 8,
minStorageGib: 16,
},
},
},
market: {
rentHours: 12,
pricing: {
maxStartPrice: 1,
maxCpuPerHourPrice: 1,
maxEnvPerHourPrice: 1,
market: {
rentHours: 12,
pricing: {
maxStartPrice: 1,
maxCpuPerHourPrice: 1,
maxEnvPerHourPrice: 1,
},
withProviders: ["0x123123"],
withoutProviders: ["0x123123"],
withOperators: ["0x123123"],
withoutOperators: ["0x123123"],
},
withProviders: ["0x123123"],
withoutProviders: ["0x123123"],
withOperators: ["0x123123"],
withoutOperators: ["0x123123"],
},
deployment: {
replicas: 3,
network: "basic",
},
})
.createActivityPool("db", {
demand: {
image: "golem/redis",
resources: {
minCpu: 2,
minMemGib: 16,
minStorageGib: 4,
deployment: {
replicas: 3,
network: "basic",
},
},
market: {
rentHours: 12 /* REQUIRED */,
pricing: {
maxStartPrice: 1 /* REQUIRED */,
maxCpuPerHourPrice: 1 /* REQUIRED */,
maxEnvPerHourPrice: 1 /* REQUIRED */,
})
.createActivityPool("db", {
demand: {
image: "golem/redis",
resources: {
minCpu: 2,
minMemGib: 16,
minStorageGib: 4,
},
},
},
deployment: {
replicas: { min: 3, max: 4 },
network: "basic",
},
});

const deployment = builder.getDeployment();
market: {
rentHours: 12 /* REQUIRED */,
pricing: {
maxStartPrice: 1 /* REQUIRED */,
maxCpuPerHourPrice: 1 /* REQUIRED */,
maxEnvPerHourPrice: 1 /* REQUIRED */,
},
},
deployment: {
replicas: { min: 3, max: 4 },
network: "basic",
},
});

await deployment.start();
const deployment = builder.getDeployment();

const activityPoolApp = deployment.getActivityPool("app");
const activity1 = await activityPoolApp.acquire();
await deployment.start();

const result = await activity1.run("node -v");
console.log(result.stdout);
await activityPoolApp.release(activity1);
// await activityPoolApp.stop();
await activityPoolApp.drain();
const activityPoolApp = deployment.getActivityPool("app");
const activity1 = await activityPoolApp.acquire();

const result2 = await deployment.getActivityPool("db").runOnce((ctx) => ctx.run("redis -v"));
console.log(result2.stdout);
const result = await activity1.run("node -v");
console.log(result.stdout);
await activityPoolApp.release(activity1);
// await activityPoolApp.stop();
await activityPoolApp.drain();

await deployment.stop();
const result2 = await deployment.getActivityPool("db").runOnce((ctx) => ctx.run("redis -v"));
console.log(result2.stdout);

await golem.disconnect();
await deployment.stop();
} catch (err) {
console.error("Failed to run the example", err);
} finally {
await golem.disconnect();
}
}

main().catch(console.error);
5 changes: 4 additions & 1 deletion examples/pool/hello-world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import {
} from "@golem-sdk/golem-js";

(async function main() {
const yagnaApi = new YagnaApi();

try {
const yagnaApi = new YagnaApi();
await yagnaApi.connect();
const modules = {
market: new MarketModuleImpl(yagnaApi),
Expand Down Expand Up @@ -56,5 +57,7 @@ import {
await activityPool.drain();
} catch (err) {
console.error("Pool execution failed:", err);
} finally {
await yagnaApi.disconnect();
}
})();

0 comments on commit 2e2da8b

Please sign in to comment.