From d0c2149379783f6766e522bb5575e74a15c8d899 Mon Sep 17 00:00:00 2001 From: shadeofblue Date: Tue, 8 Dec 2020 11:29:51 +0100 Subject: [PATCH] B0.2 (#65) * Sign new agreements only if there are unassigned tasks (#76) * Sign new agreements only if there are unassigned tasks * Display a nice message when the computation is interrupted * Update package.json * version bump Co-authored-by: filipgolem <44880692+filipgolem@users.noreply.github.com> Co-authored-by: Filip Co-authored-by: Muhammed Tanrikulu --- examples/package.json | 2 +- package.json | 2 +- yajsapi/runner/index.ts | 9 +++++++-- yajsapi/runner/smartq.ts | 4 ++++ 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/examples/package.json b/examples/package.json index 7a69a66e1..272ec99c9 100644 --- a/examples/package.json +++ b/examples/package.json @@ -16,7 +16,7 @@ "bluebird": "^3.5.0", "dayjs": "^1.8.31", "ts-node": "^9.0.0", - "yajsapi": "^0.2.0" + "yajsapi": "^0.2.1" }, "devDependencies": { "tsconfig-paths": "^3.9.0", diff --git a/package.json b/package.json index b000cbaf1..2b4245afb 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yajsapi", - "version": "0.2.0", + "version": "0.2.1", "description": "NodeJS API for Next Golem", "repository": "https://github.com/golemfactory/yajsapi", "main": "dist/index.js", diff --git a/yajsapi/runner/index.ts b/yajsapi/runner/index.ts index deb2bacfe..69db3ec4b 100755 --- a/yajsapi/runner/index.ts +++ b/yajsapi/runner/index.ts @@ -608,7 +608,8 @@ export class Engine { await sleep(2); if ( Object.keys(offer_buffer).length > 0 && - workers.size < self._conf.max_workers + workers.size < self._conf.max_workers && + work_queue.has_unassigned_items() ) { let _offer_list = Object.entries(offer_buffer); let _sample = @@ -713,7 +714,11 @@ export class Engine { } emit(new events.ComputationFinished()); } catch (error) { - logger.error(`fail= ${error}`); + if (error === undefined) { // this needs more research + logger.error("Computation interrupted by the user."); + } else { + logger.error(`fail= ${error}`); + } if (!self._worker_cancellation_token.cancelled) self._worker_cancellation_token.cancel(); // TODO: implement ComputationFinished(error) diff --git a/yajsapi/runner/smartq.ts b/yajsapi/runner/smartq.ts index 38d03ed0d..3fe89e454 100644 --- a/yajsapi/runner/smartq.ts +++ b/yajsapi/runner/smartq.ts @@ -142,6 +142,10 @@ export class SmartQueue { await promisify(csp.takeAsync)(this.__eof); } } + + has_unassigned_items(): boolean { + return !!(this._items && this._items.length) || !!this._rescheduled_items.size + } } export class Consumer {