Skip to content
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

Add 5s timeout for market operations #305

Merged
merged 2 commits into from
Mar 31, 2021
Merged

Conversation

azawlocki
Copy link
Contributor

@azawlocki azawlocki commented Mar 30, 2021

This could serve as a hotfix/work-around for #304.

For the next release we should think about making the code in collect_offers() more concurrent, for example delegate processing of each offer to a pool 5 of asyncio tasks.

@azawlocki azawlocki changed the title Add 5s timeout for market operations [WIP] Add 5s timeout for market operations Mar 30, 2021
@azawlocki azawlocki self-assigned this Mar 30, 2021
@@ -368,6 +368,32 @@ async def accept_payment_for_agreement(agreement_id: str, *, partial: bool = Fal
)

async def find_offers() -> None:
async def reject_proposal(proposal, reason):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm... the only thing I'm concerned about is that again, we're adding inner-scope functions ... whereas maybe we should start pulling that stuff outside ... but I do understand that the milk is spilled by find_offers already so it would be artificial to pull these as methods and leave find_offers as internal...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes inner functions are just better - object-oriented programming is not the only paradigm, let's not be afraid of them. Actually, I like @azawlocki's solution very much, it's an improvement over the original code and over my PR to yajsapi, which AFAIR added another copy of try/call api/catch/emit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These functions are not visible outside of find_offers(). If they are not used outside, IMO they shouldn't be moved as they are "helper" functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shadeofblue I've just started pulling stuff outside in #306, I'm not sure we want to do that kind of refactoring in a PR to a release branch.

Copy link
Contributor

@shadeofblue shadeofblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apart from the more general remark about inner scope functions, it looks good to me

still, I'd wait for @filipgolem to have a look

@@ -368,6 +368,32 @@ async def accept_payment_for_agreement(agreement_id: str, *, partial: bool = Fal
)

async def find_offers() -> None:
async def reject_proposal(proposal, reason):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes inner functions are just better - object-oriented programming is not the only paradigm, let's not be afraid of them. Actually, I like @azawlocki's solution very much, it's an improvement over the original code and over my PR to yajsapi, which AFAIR added another copy of try/call api/catch/emit.

with contextlib.suppress(Exception):
await proposal.reject(reason="Score too low")
emit(events.ProposalRejected(prop_id=proposal.id, reason="Score too low"))
await reject_proposal(proposal, "Score too low")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not required, because there is no code after all if branches, but maybe we can add continue after the call to show our intent? Feel free to ignore this suggestion.

Suggested change
await reject_proposal(proposal, "Score too low")
await reject_proposal(proposal, "Score too low")
continue

@azawlocki azawlocki changed the title [WIP] Add 5s timeout for market operations Add 5s timeout for market operations Mar 31, 2021
@azawlocki azawlocki merged commit 464f3f3 into b0.5 Mar 31, 2021
@azawlocki azawlocki deleted the az/timeouts-for-market-ops branch March 31, 2021 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants