Skip to content

Commit

Permalink
Merge pull request #1091 from golemfactory/beta
Browse files Browse the repository at this point in the history
Beta -> master
  • Loading branch information
SewerynKras authored Sep 25, 2024
2 parents 6fa5fcb + 2c70207 commit 9f385e3
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 63 deletions.
4 changes: 2 additions & 2 deletions examples/experimental/job/cancel.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { JobManager } from "@golem-sdk/golem-js/experimental";
import { MarketOrderSpec } from "@golem-sdk/golem-js";
const golem = new JobManager({
yagna: {
apiKey: "try_golem",
api: {
key: "try_golem",
},
});

Expand Down
4 changes: 2 additions & 2 deletions examples/experimental/job/getJobById.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { JobManager } from "@golem-sdk/golem-js/experimental";
import { MarketOrderSpec } from "@golem-sdk/golem-js";

const golem = new JobManager({
yagna: {
apiKey: "try_golem",
api: {
key: "try_golem",
},
});

Expand Down
4 changes: 2 additions & 2 deletions examples/experimental/job/waitForResults.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { JobManager } from "@golem-sdk/golem-js/experimental";
import { MarketOrderSpec } from "@golem-sdk/golem-js";
const golem = new JobManager({
yagna: {
apiKey: "try_golem",
api: {
key: "try_golem",
},
});

Expand Down
3 changes: 3 additions & 0 deletions examples/rental-model/advanced/gpu-ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import chalk from "chalk";
logger: pinoPrettyLogger({
level: "info",
}),
payment: {
network: "polygon",
},
});

try {
Expand Down
3 changes: 3 additions & 0 deletions examples/rental-model/advanced/gpu/gpu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { pinoPrettyLogger } from "@golem-sdk/pino-logger";
logger: pinoPrettyLogger({
level: "info",
}),
payment: {
network: "polygon",
},
});

const order: MarketOrderSpec = {
Expand Down
31 changes: 16 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 1 addition & 11 deletions src/experimental/job/job.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { ExeUnitOptions, ExeUnit } from "../../activity/exe-unit";
import { NetworkOptions } from "../../network";
import { PaymentModuleOptions } from "../../payment";
import { ExeUnit } from "../../activity/exe-unit";
import { EventEmitter } from "eventemitter3";
import { GolemAbortError, GolemUserError } from "../../shared/error/golem-error";
import { GolemNetwork, MarketOrderSpec } from "../../golem-network/golem-network";
import { Logger } from "../../shared/utils";
import { WorkloadDemandDirectorConfigOptions } from "../../market/demand/options";

export enum JobState {
New = "new",
Expand All @@ -16,13 +13,6 @@ export enum JobState {
Rejected = "rejected",
}

export type RunJobOptions = {
payment?: PaymentModuleOptions;
network?: NetworkOptions;
workload?: WorkloadDemandDirectorConfigOptions;
work?: ExeUnitOptions;
};

export type WorkFunction<OutputType> = (exe: ExeUnit) => Promise<OutputType>;

export interface JobEventsDict {
Expand Down
41 changes: 11 additions & 30 deletions src/experimental/job/job_manager.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { v4 } from "uuid";
import { Job, RunJobOptions } from "./job";
import { defaultLogger, Logger, YagnaOptions, isNode, isBrowser } from "../../shared/utils";
import { Job } from "./job";
import { defaultLogger, Logger, YagnaOptions } from "../../shared/utils";
import { GolemUserError } from "../../shared/error/golem-error";
import { GolemNetwork, MarketOrderSpec } from "../../golem-network/golem-network";
import {
GftpStorageProvider,
NullStorageProvider,
StorageProvider,
WebSocketBrowserStorageProvider,
} from "../../shared/storage";
import { GolemNetwork, GolemNetworkOptions, MarketOrderSpec } from "../../golem-network/golem-network";

export type JobManagerConfig = Partial<RunJobOptions> & {
export type JobManagerConfig = Partial<GolemNetworkOptions> & {
/**
* @deprecated This field is deprecated and will be removed in future versions. Please use the 'api.key` and `api.url' instead.
*/
yagna?: YagnaOptions;
};

Expand All @@ -28,20 +25,16 @@ export class JobManager {
* @param logger
*/
constructor(
private readonly config?: JobManagerConfig,
config?: JobManagerConfig,
private readonly logger: Logger = defaultLogger("jobs"),
) {
const storageProvider = this.getDefaultStorageProvider();

this.logger.debug("Jobs using storage provider", { storageProvider });

this.glm = new GolemNetwork({
api: {
key: this.config?.yagna?.apiKey,
url: this.config?.yagna?.basePath,
key: config?.yagna?.apiKey,
url: config?.yagna?.basePath,
},
dataTransferProtocol: storageProvider,
logger: this.logger,
...config,
});
}

Expand Down Expand Up @@ -89,16 +82,4 @@ export class JobManager {
throw new GolemUserError("GolemNetwork not initialized, please run init() first");
}
}

private getDefaultStorageProvider(): StorageProvider {
if (isNode) {
return new GftpStorageProvider();
}

if (isBrowser) {
return new WebSocketBrowserStorageProvider(this.glm.services.yagna, {});
}

return new NullStorageProvider();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class WorkloadDemandDirectorConfig extends BaseConfig {

Object.assign(this, options);

if (!this.runtime.name) {
if (!options.runtime?.name) {
this.runtime.name = this.engine;
}

Expand Down
17 changes: 17 additions & 0 deletions src/market/demand/directors/workload-demand-director.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,21 @@ describe("ActivityDemandDirector", () => {
"The engine parameter is deprecated and cannot be used with the runtime parameter. Use the runtime option only",
);
});

test("should use deprecated engine param as runtime name", async () => {
const builder = new DemandBodyBuilder();

const director = new WorkloadDemandDirector(
new WorkloadDemandDirectorConfig({
engine: "vm-test",
expirationSec: 2,
imageHash: "529f7fdaf1cf46ce3126eb6bbcd3b213c314fe8fe884914f5d1106d4",
}),
);
await director.apply(builder);

const decorations = builder.getProduct();

expect(decorations.constraints).toEqual(expect.arrayContaining(["(golem.runtime.name=vm-test)"]));
});
});

0 comments on commit 9f385e3

Please sign in to comment.