Skip to content

Commit

Permalink
Update the message about the agreement expiration being out of bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
azawlocki committed Jun 2, 2021
1 parent 272f0c0 commit c06ae3c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
7 changes: 5 additions & 2 deletions yapapi/executor/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
16 changes: 11 additions & 5 deletions yapapi/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit c06ae3c

Please sign in to comment.