From c06ae3c71bbcb8badce6cd671ccb7e2fdd257302 Mon Sep 17 00:00:00 2001 From: azawlocki Date: Wed, 2 Jun 2021 12:45:05 +0200 Subject: [PATCH] Update the message about the agreement expiration being out of bounds --- yapapi/executor/services.py | 7 +++++-- yapapi/log.py | 16 +++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/yapapi/executor/services.py b/yapapi/executor/services.py index c5c39e7e7..0bf5387fc 100644 --- a/yapapi/executor/services.py +++ b/yapapi/executor/services.py @@ -29,8 +29,11 @@ logger = logging.getLogger(__name__) -# current default for yagna providers as of yagna 0.6.x -DEFAULT_SERVICE_EXPIRATION: Final[timedelta] = timedelta(minutes=175) +# current defaults for yagna providers as of yagna 0.6.x, see +# https://github.com/golemfactory/yagna/blob/c37dbd1a2bc918a511eed12f2399eb9fd5bbf2a2/agent/provider/src/market/negotiator/factory.rs#L20 +MIN_AGREEMENT_EXPIRATION: Final[timedelta] = timedelta(minutes=5) +MAX_AGREEMENT_EXPIRATION: Final[timedelta] = timedelta(minutes=180) +DEFAULT_SERVICE_EXPIRATION: Final[timedelta] = MAX_AGREEMENT_EXPIRATION - timedelta(minutes=5) cluster_ids = itertools.count(1) diff --git a/yapapi/log.py b/yapapi/log.py index bb6f22906..18307353f 100644 --- a/yapapi/log.py +++ b/yapapi/log.py @@ -53,8 +53,9 @@ import time from typing import Any, Callable, Dict, Iterator, List, Optional, Set -import yapapi.executor.events as events from yapapi import __version__ as yapapi_version +import yapapi.executor.events as events +from yapapi.executor.services import MAX_AGREEMENT_EXPIRATION, MIN_AGREEMENT_EXPIRATION from yapapi.rest.activity import CommandExecutionError event_logger = logging.getLogger("yapapi.events") @@ -350,13 +351,18 @@ def _handle(self, event: events.Event): # This means another computation run in the current Executor instance. self._print_total_cost(partial=True) timeout = event.expires - datetime.now(timezone.utc) - if not timedelta(minutes=5, seconds=5) <= timeout <= timedelta(minutes=30): + # Compute the timeout as it will be seen by providers, assuming they will see + # the Demand 5 seconds from now + provider_timeout = timeout - timedelta(seconds=5) + if not MIN_AGREEMENT_EXPIRATION <= provider_timeout <= MAX_AGREEMENT_EXPIRATION: min, sec = divmod(round(timeout.total_seconds()), 60) + seconds_str = f" {sec} sec " if sec else " " + max_minutes = round(MAX_AGREEMENT_EXPIRATION.seconds / 60) self.logger.warning( - f"Expiration time for your tasks is set to {min} min {sec} sec from now." + f"Expiration time for your tasks is set to {min} min{seconds_str}from now." " Providers may not be willing to take up tasks which expire sooner than 5 min" - " or later than 3 hours, counting from the moment they get your demand." - " Use the `timeout` parameter to `Executor()` to adjust the timeout." + f" or later than {max_minutes} min, counting from the moment they get your" + " demand." ) elif isinstance(event, events.ProposalReceived):