-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Release 0.7.5 #157
Merged
Merged
Release 0.7.5 #157
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ba40244
More default payloads
approxit 2100791
Extra in WorkContext
approxit a6e885a
Updated payment manager internals
approxit 510d2aa
Exclamation mark support in constraints
approxit e71a52d
SingleUseDemandManager support
approxit 3366e1e
Release 0.7.5
approxit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import logging | ||
from itertools import chain | ||
from typing import Awaitable, Callable, Sequence | ||
|
||
from golem.managers.base import DemandManager | ||
from golem.managers.mixins import BackgroundLoopMixin | ||
from golem.node import GolemNode | ||
from golem.payload import Payload | ||
from golem.payload import defaults as payload_defaults | ||
from golem.resources import Allocation, Demand, Proposal | ||
from golem.resources.demand.demand_builder import DemandBuilder | ||
from golem.utils.asyncio import ErrorReportingQueue | ||
from golem.utils.logging import trace_span | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class SingleUseDemandManager(BackgroundLoopMixin, DemandManager): | ||
"""DemandManager that creates one single demand as a single source of initial proposals.""" | ||
|
||
def __init__( | ||
self, | ||
golem: GolemNode, | ||
get_allocation: Callable[[], Awaitable[Allocation]], | ||
payloads: Sequence[Payload], | ||
) -> None: | ||
self._golem = golem | ||
self._get_allocation = get_allocation | ||
self._payloads = payloads | ||
|
||
self._initial_proposals: ErrorReportingQueue[Proposal] = ErrorReportingQueue() | ||
|
||
super().__init__() | ||
|
||
@trace_span("Starting SingleUseDemandManager", log_level=logging.INFO) | ||
async def start(self) -> None: | ||
return await super().start() | ||
|
||
@trace_span("Stopping SingleUseDemandManager", log_level=logging.INFO) | ||
async def stop(self) -> None: | ||
return await super().stop() | ||
|
||
@trace_span("Getting initial proposal", show_results=True) | ||
async def get_initial_proposal(self) -> Proposal: | ||
proposal = await self._initial_proposals.get() | ||
self._initial_proposals.task_done() | ||
return proposal | ||
|
||
@trace_span() | ||
async def _background_loop(self) -> None: | ||
demand = await self._create_and_subscribe_demand() | ||
demand.start_collecting_events() | ||
|
||
try: | ||
await self._consume_initial_proposals(demand) | ||
except Exception as e: | ||
self._initial_proposals.set_exception(e) | ||
logger.debug( | ||
"Encountered unexpected exception while handling demands," | ||
" exception is set and background loop will be stopped!" | ||
) | ||
finally: | ||
await demand.unsubscribe() | ||
|
||
@trace_span() | ||
async def _create_and_subscribe_demand(self): | ||
allocation = await self._get_allocation() | ||
demand_builder = await self._prepare_demand_builder(allocation) | ||
logger.debug(f"Creating demand: {demand_builder=}") | ||
demand = await demand_builder.create_demand(self._golem) | ||
|
||
return demand | ||
|
||
@trace_span() | ||
async def _prepare_demand_builder(self, allocation: Allocation) -> DemandBuilder: | ||
# FIXME: Code looks duplicated as GolemNode.create_demand does the same | ||
demand_builder = DemandBuilder() | ||
|
||
for demand_spec in chain( | ||
[ | ||
payload_defaults.ActivityInfo( | ||
lifetime=payload_defaults.DEFAULT_LIFETIME, multi_activity=True | ||
), | ||
payload_defaults.PaymentInfo(), | ||
await allocation.get_demand_spec(), | ||
], | ||
self._payloads, | ||
): | ||
await demand_builder.add(demand_spec) | ||
|
||
return demand_builder | ||
|
||
@trace_span() | ||
async def _consume_initial_proposals(self, demand: Demand): | ||
initial_proposals_gen = demand.initial_proposals() | ||
first_initial_proposal = await initial_proposals_gen.__anext__() | ||
logger.info("Received first initial proposal") | ||
|
||
logger.debug(f"New initial proposal {first_initial_proposal}") | ||
self._initial_proposals.put_nowait(first_initial_proposal) | ||
|
||
async for initial in initial_proposals_gen: | ||
logger.debug(f"New initial proposal {initial}") | ||
self._initial_proposals.put_nowait(initial) |
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 |
---|---|---|
|
@@ -23,7 +23,7 @@ ConstraintOperator: | |
; | ||
|
||
PropertyName: | ||
/[\w-]+(\.[\w-]+)*/ | ||
/[\w!-]+(\.[\w!-]+)*/ | ||
; | ||
|
||
PropertyValueList: | ||
|
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "golem-core" | ||
version = "0.7.4" | ||
version = "0.7.5" | ||
description = "Golem Network (https://golem.network/) API for Python" | ||
authors = ["Golem Factory <[email protected]>"] | ||
license = "LGPL-3.0-or-later" | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have a pydoc that describes what is special about this one so it is easier to tell how it is different then other managers of the same type.