Skip to content

Commit

Permalink
feat: combine agreement and activity pools into leaseprocesspool
Browse files Browse the repository at this point in the history
  • Loading branch information
SewerynKras committed May 8, 2024
1 parent 605311b commit 4ccff3a
Show file tree
Hide file tree
Showing 17 changed files with 413 additions and 479 deletions.
35 changes: 15 additions & 20 deletions examples/pool/hello-world.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ActivityPool, AgreementPool, DraftOfferProposalPool, GolemNetwork } from "@golem-sdk/golem-js";
import { DraftOfferProposalPool, GolemNetwork } from "@golem-sdk/golem-js";
import { pinoPrettyLogger } from "@golem-sdk/pino-logger";

(async () => {
Expand All @@ -15,9 +15,11 @@ import { pinoPrettyLogger } from "@golem-sdk/pino-logger";
},
},
});
let allocation;

try {
await glm.connect();
allocation = await glm.payment.createAllocation({ budget: 1 });

const demandOptions = {
demand: {
Expand Down Expand Up @@ -50,10 +52,6 @@ import { pinoPrettyLogger } from "@golem-sdk/pino-logger";

const proposalSubscription = proposalPool.readFrom(proposals$);

// TODO: allocation is not used in this example?
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const allocation = await glm.payment.createAllocation({ budget: 1 });

/** How many providers you plan to engage simultaneously */
const CONCURRENCY = 2;

Expand All @@ -63,34 +61,31 @@ import { pinoPrettyLogger } from "@golem-sdk/pino-logger";
payment: glm.payment,
};

// TODO: Optimize constructor params
const agreementPool = new AgreementPool(proposalPool, glm.services.agreementApi, {
const pool = depModules.market.createLeasePool(proposalPool, allocation, {
replicas: { max: CONCURRENCY },
logger,
});

const activityPool = new ActivityPool(depModules, agreementPool, {
replicas: CONCURRENCY,
logger,
});

const ctx = await activityPool.acquire();
const result = await ctx.run("echo Hello World");
const lease = await pool.acquire();
const exe = await lease.getExeUnit();
const result = await exe.run("echo Hello World");
console.log(result.stdout);

const ctx2 = await activityPool.acquire();
const result2 = await ctx.run("echo Hello Golem");
const lease2 = await pool.acquire();
const exe2 = await lease2.getExeUnit();
const result2 = await exe2.run("echo Hello Golem");
console.log(result2.stdout);

await activityPool.release(ctx);
await activityPool.release(ctx2);
await pool.release(lease);
await pool.release(lease2);

proposalSubscription.unsubscribe();
await activityPool.drainAndClear();
await agreementPool.drainAndClear();
await pool.drainAndClear();
await allocation.release();
} catch (err) {
console.error("Pool execution failed:", err);
} finally {
await glm.disconnect();
allocation?.release();
}
})().catch(console.error);
18 changes: 0 additions & 18 deletions src/activity/activity-pool.test.ts

This file was deleted.

173 changes: 0 additions & 173 deletions src/activity/activity-pool.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/activity/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export { Activity, ActivityStateEnum } from "./activity";
export { Result } from "./results";
export { ExecutionConfig } from "./config";
export { ActivityPool, ActivityPoolOptions, ActivityPoolEvents } from "./activity-pool";
export * from "./activity.module";
Loading

0 comments on commit 4ccff3a

Please sign in to comment.