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 support for a new ParallelManager#execute method. #1584

Merged
merged 2 commits into from
Aug 22, 2024

Conversation

iMacTia
Copy link
Member

@iMacTia iMacTia commented Aug 21, 2024

Description

The new interface passes the parallel block with all the requests to the ParallelManager, instead of running it beforehand.

This allows for better, stateless ParallelManager implementations.

Fixes #1583

Todos

List any remaining work that needs to be done, i.e:

  • Tests: probably not adding any since the implementation depends on the adapter
  • Documentation

The new interface passes the parallel block with all the requests to the ParallelManager, instead of running it beforehand.

This allows for better, stateless ParallelManager implementations.

Fixes #1583
@iMacTia iMacTia force-pushed the mg/parallel-manager-execute branch from f55e7f5 to 67dea51 Compare August 21, 2024 12:42
@ioquatix
Copy link
Contributor

If you want to add tests, you could use bake-external and run the async-http-faraday test suite. You can use bake-test to execute the actual tests.

@ioquatix
Copy link
Contributor

@iMacTia can you carefully review socketry/async-http-faraday#45 to ensure I've implemented it correctly. It appears to be working.

cc @olleolleolle :)

@ioquatix
Copy link
Contributor

Thanks for working on this, it's awesome :)

@iMacTia
Copy link
Member Author

iMacTia commented Aug 22, 2024

If you want to add tests, you could use bake-external and run the async-http-faraday test suite. You can use bake-test to execute the actual tests.

I actually tried this locally because we already use bake-external to test against net_http (the default adapter) but I got a failure unrelated to this change (something to do with Google redirection).

When I get more time I'll give it another go 👍 thanks for the suggestion

Copy link
Member

@olleolleolle olleolleolle left a comment

Choose a reason for hiding this comment

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

Lovely!

def call(env)
# NB: you can call `in_parallel?` here to check if the current request
# is part of a parallel batch. Useful if you need to collect all requests
# into the ParallelManager before running them.
Copy link
Member

Choose a reason for hiding this comment

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

This context-giving comment is gold.

end
end
```

Compare to the finished example [em-synchrony](https://github.com/lostisland/faraday-em_synchrony/blob/main/lib/faraday/adapter/em_synchrony.rb)
### A note on the old, deprecated interface
Copy link
Member

Choose a reason for hiding this comment

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

Oh, and so good with this note!

docs/adapters/custom/parallel-requests.md Outdated Show resolved Hide resolved
# Execute is the new method that is responsible for executing the block.
@parallel_manager.execute(&block)
else
# TODO: Old behaviour, deprecate and remove in 3.0
Copy link
Member

Choose a reason for hiding this comment

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

(Very kind not to emit deprecation warnings, here!)

@iMacTia iMacTia merged commit 3835b48 into main Aug 22, 2024
7 checks passed
@iMacTia iMacTia deleted the mg/parallel-manager-execute branch August 22, 2024 12:05
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.

Async::HTTP::Faraday cannot use "in_parallel"
3 participants