Skip to content

Commit

Permalink
refactor: removing deprecated methods
Browse files Browse the repository at this point in the history
* chore(payment): removed deprecated acceptDebitNotes method
* refactor: fixed remaining usage of a removed method
* refactor: removing deprecated methods

BREAKING CHANGE:
* `PaymentService.acceptDebitNote` is no longer available, use `acceptPayments` instead.
* Deprecated `isSubprocess` TaskExecutor option is now removed.
* Deprecated `TaskExecutor.end` is now removed (use `TaskExecutor.shutdown` instead)
* Deprecated `TaskExecutor.beforeEach` is now removed (use `TaskExecutor.onActivityReady` instead)
* Deprecated `WorkContext.rejectResult` method is removed.
  • Loading branch information
grisha87 authored Jan 29, 2024
1 parent 2424415 commit b79e770
Show file tree
Hide file tree
Showing 13 changed files with 11 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ <h3>Logs</h3>
})
.catch((e) => logger.error(e));

await executor.end();
await executor.shutdown();
if (result?.data) setResponse(result.data);
}
document.getElementById("RUN").onclick = run;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
appendResults(JSON.stringify(output.data.output, null, "\t"));
})
.catch((e) => logger.error(e));
await executor.end();
await executor.shutdown();
}
document.getElementById("echo").onclick = run;
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function run() {
} catch (error) {
logger.error("Computation failed:", error);
} finally {
await executor.end();
await executor.shutdown();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ const url = "https://ipfs.io/ipfs/bafybeihkoviema7g3gxyt6la7vd5ho32ictqbilu3wnlo
} catch (err) {
console.error("The task failed due to", err);
} finally {
await executor.end();
await executor.shutdown();
}
})();
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ <h3>Logs</h3>
await executor
.run(async (ctx) => appendResults((await ctx.run("echo 'Hello World'")).stdout))
.catch((e) => logger.error(e));
await executor.end();
await executor.shutdown();
}
document.getElementById("echo").onclick = run;
</script>
Expand Down
7 changes: 3 additions & 4 deletions examples/package-lock.json

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

2 changes: 1 addition & 1 deletion examples/simple-usage/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ const finalResult = await executor.run(async (ctx) => {

console.log(finalResult);

await executor.end();
await executor.shutdown();
42 changes: 0 additions & 42 deletions src/executor/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ export type ExecutorOptions = {
maxTaskRetries?: number;
/** Custom Storage Provider used for transfer files */
storageProvider?: StorageProvider;
/**
* @deprecated this parameter will be removed in the next version.
* Currently, has no effect on executor termination.
*/
isSubprocess?: boolean;
/** Timeout for preparing activity - creating and deploy commands */
activityPreparingTimeout?: number;
/**
Expand Down Expand Up @@ -276,17 +271,6 @@ export class TaskExecutor {
this.events.emit("ready");
}

/**
* Stop all executor services and shut down executor instance.
*
* You can call this method multiple times, it will resolve only once the executor is shutdown.
*
* @deprecated Use TaskExecutor.shutdown() instead.
*/
end(): Promise<void> {
return this.shutdown();
}

/**
* Stop all executor services and shut down executor instance.
*
Expand Down Expand Up @@ -337,32 +321,6 @@ export class TaskExecutor {
return this.statsService.getStatsTree();
}

/**
* @deprecated
* Use {@link TaskExecutor.onActivityReady} instead.
*
* Define worker function that will be runs before every each computation Task, within the same activity.
*
* @param worker worker function - task
* @example
* ```typescript
* executor.beforeEach(async (ctx) => {
* await ctx.uploadFile("./params.txt", "/params.txt");
* });
*
* await executor.forEach([1, 2, 3, 4, 5], async (ctx, item) => {
* await ctx
* .beginBatch()
* .run(`/run_some_command.sh --input ${item} --params /input_params.txt --output /output.txt`)
* .downloadFile("/output.txt", "./output.txt")
* .end();
* });
* ```
*/
beforeEach(worker: Worker<unknown>) {
this.activityReadySetupFunctions = [worker];
}

/**
* Registers a worker function that will be run when an activity is ready.
* This is the perfect place to run setup functions that need to be run only once per
Expand Down
8 changes: 0 additions & 8 deletions src/market/proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ export type ProposalProperties = Record<string, string | number | string[] | num
"golem.com.payment.platform.erc20-polygon-glm.address"?: string;
"golem.com.payment.platform.erc20-holesky-tglm.address"?: string;
"golem.com.payment.platform.erc20-mumbai-tglm.address"?: string;
/**
* @deprecated rinkeby is no longer supported, use other test networks instead
*/
"golem.com.payment.platform.erc20-rinkeby-tglm.address"?: string;
/**
* @deprecated rinkeby is no longer supported, use other test networks instead
*/
"golem.com.payment.platform.zksync-rinkeby-tglm.address"?: string;
"golem.com.pricing.model": "linear";
"golem.com.pricing.model.linear.coeffs": number[];
"golem.com.scheme": string;
Expand Down
13 changes: 0 additions & 13 deletions src/payment/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,6 @@ export class PaymentService {
);
}

/**
* @deprecated, Use `acceptPayments` instead
*/
// Reason: We will remove this in 2.0
// eslint-disable-next-line @typescript-eslint/no-unused-vars
acceptDebitNotes(_agreementId: string) {
this.logger.warn(
"PaymentService.acceptDebitNotes is deprecated and will be removed in the next major version. " +
"Use PaymentService.acceptPayments which now also deal with debit notes.",
);
return;
}

private getNumberOfUnpaidAgreements() {
const inProgress = [...this.processes.values()].filter((p) => !p.isFinished());

Expand Down
7 changes: 0 additions & 7 deletions src/task/work.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,6 @@ export class WorkContext {
return Batch.create(this.activity, this.storageProvider, this.logger);
}

/**
* @Deprecated This function is only used to throw errors from unit tests. It should be removed.
*/
rejectResult(msg: string) {
throw new GolemError(`Work rejected. Reason: ${msg}`);
}

getWebsocketUri(port: number): string {
if (!this.networkNode) throw new GolemError("There is no network in this work context");
return this.networkNode.getWebsocketUri(port);
Expand Down
7 changes: 2 additions & 5 deletions tests/mock/services/payment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Allocation } from "../../../src/payment/allocation";
import { PaymentService } from "../../../src/payment";
import { Allocation } from "../../../src/payment";
import { PaymentService } from "../../../src";
import { allocationMock } from "../../mock";
import { Agreement } from "../../../src/agreement";

Expand All @@ -16,7 +16,4 @@ export const paymentServiceMock: PaymentService = {
acceptPayments(agreement: Agreement) {
return true;
},
acceptDebitNotes(agreementId: string) {
return true;
},
};
34 changes: 0 additions & 34 deletions tests/unit/tasks_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,40 +124,6 @@ describe("Task Service", () => {
);
});

it("should reject task by user", async () => {
const worker = async (ctx: WorkContext) => {
const result = await ctx.run("some_shell_command");
if (result.stdout === "invalid_value") ctx.rejectResult("Invalid value computed by provider");
};
const task = new Task("1", worker, { maxRetries: 2 });
queue.addToEnd(task);
activityMock.setExpectedExeResults([{ result: "Ok", stdout: "invalid_value" }]);
const service = new TaskService(
new YagnaMock().getApi(),
queue,
agreementPoolServiceMock,
paymentServiceMock,
networkServiceMock,
{
logger,
taskRunningInterval: 10,
activityStateCheckingInterval: 10,
},
);
service.run().catch((e) => console.error(e));

await logger.expectToInclude(
"Task has been rejected",
{
taskId: task.id,
reason: "Work rejected. Reason: Invalid value computed by provider",
},
1500,
);
expect(task.isFinished()).toEqual(true);
await service.end();
});

it("should reject task if it failed max attempts", async () => {
const worker = async (ctx: WorkContext) => ctx.run("some_shell_command");
const task = new Task("1", worker, { maxRetries: 1 });
Expand Down

0 comments on commit b79e770

Please sign in to comment.