Skip to content

Commit

Permalink
fix(job): fixed passing payment param in JobManagerConfig
Browse files Browse the repository at this point in the history
refactor(job): improved JobManagerConfig type to include full GolemNetwork configuration
  • Loading branch information
mgordel committed Sep 24, 2024
1 parent 8db36dc commit e97c66b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 47 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
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> & {
/** Type of engine required: vm, wasm, vm-nvidia, etc...
* @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();
}
}

0 comments on commit e97c66b

Please sign in to comment.