diff --git a/examples/package.json b/examples/package.json index 06a8a40..72837a5 100644 --- a/examples/package.json +++ b/examples/package.json @@ -34,7 +34,7 @@ "node": ">=18" }, "dependencies": { - "@golem-sdk/golem-js": "^3.2.0", + "@golem-sdk/golem-js": "^3.3.0", "@golem-sdk/pino-logger": "^1.1.0", "@golem-sdk/task-executor": "file:..", "commander": "^12.0.0", diff --git a/package-lock.json b/package-lock.json index 6d3e1ba..969cef5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "examples" ], "dependencies": { - "@golem-sdk/golem-js": "^3.2.0", + "@golem-sdk/golem-js": "^3.3.0", "eventemitter3": "^5.0.1" }, "devDependencies": { @@ -59,10 +59,11 @@ } }, "examples": { + "name": "golem-js-examples", "version": "0.0.0", "license": "LGPL-3.0", "dependencies": { - "@golem-sdk/golem-js": "^3.2.0", + "@golem-sdk/golem-js": "^3.3.0", "@golem-sdk/pino-logger": "^1.1.0", "@golem-sdk/task-executor": "file:..", "commander": "^12.0.0", @@ -1403,15 +1404,19 @@ "dev": true }, "node_modules/@golem-sdk/golem-js": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/@golem-sdk/golem-js/-/golem-js-3.2.0.tgz", - "integrity": "sha512-rU0sFYQ7n2VxXvs7VRojBkWV+cBqWWGoehTJHdx1XKmra0p2CNdTzfOq0sRCjg7s8vUgVWl0xu++acE7HiwD6w==", + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/@golem-sdk/golem-js/-/golem-js-3.3.0.tgz", + "integrity": "sha512-pN8Yv+hwxKIsl3jDw9k2lIchCmzv4z1uEq7/ExCYb6HW6MPrTvD+nYCyiNZ0OK30MtsjkDwyTqCAD/jBXQsu/w==", + "workspaces": [ + "examples/" + ], "dependencies": { "@golem-sdk/pino-logger": "^1.1.0", "async-lock": "^1.4.1", "async-retry": "^1.3.3", "axios": "^1.6.7", "bottleneck": "^2.19.5", + "cross-spawn": "^7.0.3", "debug": "^4.3.4", "decimal.js-light": "^2.5.1", "eventemitter3": "^5.0.1", @@ -6440,7 +6445,6 @@ "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", - "dev": true, "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", @@ -9372,8 +9376,7 @@ "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", - "dev": true + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" }, "node_modules/isstream": { "version": "0.1.2", @@ -15764,7 +15767,6 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", - "dev": true, "engines": { "node": ">=8" } @@ -17802,7 +17804,6 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", - "dev": true, "dependencies": { "shebang-regex": "^3.0.0" }, @@ -17814,7 +17815,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", - "dev": true, "engines": { "node": ">=8" } @@ -19718,7 +19718,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", - "dev": true, "dependencies": { "isexe": "^2.0.0" }, diff --git a/package.json b/package.json index ee46b29..bf4977d 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "node": ">=18.0.0" }, "dependencies": { - "@golem-sdk/golem-js": "^3.2.0", + "@golem-sdk/golem-js": "^3.3.0", "eventemitter3": "^5.0.1" }, "devDependencies": { diff --git a/src/service.ts b/src/service.ts index 9fc1ec6..04c312c 100644 --- a/src/service.ts +++ b/src/service.ts @@ -77,6 +77,8 @@ export class TaskService { } private async startTask(task: Task) { + const abortController = new AbortController(); + const { signal, cleanup } = anyAbortSignal(this.abortController.signal, abortController.signal); try { task.init(); this.logger.debug(`Starting task`, { taskId: task.id, attempt: task.getRetriesCount() + 1 }); @@ -85,13 +87,11 @@ export class TaskService { throw new GolemInternalError(`Execution of task ${task.id} aborted due to error. ${task.getError()}`); } - const abortController = new AbortController(); task.onStateChange((state) => { if (state === TaskState.Rejected || state === TaskState.Retry) { abortController.abort(); } }); - const signal = anyAbortSignal(this.abortController.signal, abortController.signal); const rental = await this.resourceRentalPool.acquire(signal); if (task.isFailed()) { @@ -116,6 +116,8 @@ export class TaskService { error, error instanceof GolemWorkError || (error instanceof GolemTimeoutError && task.retryOnTimeout), ); + } finally { + cleanup(); } }