-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from golemfactory/blue/blacklist-failing-nodes
temporarily blacklist failing providers
- Loading branch information
Showing
5 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"""Dapp runner's market strategy implementation.""" | ||
import logging | ||
from typing import Set | ||
|
||
from yapapi import rest | ||
from yapapi.strategy.wrapping_strategy import WrappingMarketStrategy | ||
|
||
BLACKLISTED_SCORE = -1.0 | ||
|
||
|
||
class BlacklistOnFailure(WrappingMarketStrategy): | ||
"""A market strategy wrapper that blacklists providers when they fail an activity.""" | ||
|
||
def __init__(self, base_strategy): | ||
"""Initialize instance. | ||
:param base_strategy: the base strategy around which this strategy is wrapped | ||
""" | ||
super().__init__(base_strategy) | ||
self._logger = logging.getLogger(f"{__name__}.{type(self).__name__}") | ||
self._blacklist: Set[str] = set() | ||
|
||
def blacklist_node(self, node_id: str): | ||
"""Add the given node id to the blacklist.""" | ||
self._blacklist.add(node_id) | ||
|
||
async def score_offer(self, offer: rest.market.OfferProposal) -> float: | ||
"""Reject the node if blacklisted, otherwise score the offer using the base strategy.""" | ||
|
||
if offer.issuer in self._blacklist: | ||
self._logger.debug( | ||
"Rejecting offer %s from a blacklisted node '%s'", offer.id, offer.issuer | ||
) | ||
return BLACKLISTED_SCORE | ||
|
||
score = await self.base_strategy.score_offer(offer) | ||
return score |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters